Drawing a Thue-Morse pattern recursively This is web exercise 3.1.63. from the book Computer Science An Interdisciplinary Approach by Sedgewick &amp; Wayne:

Write a program  that reads in a command line input N and plots the
N-by-N Thue-Morse pattern.  Below are the Thue-Morse patterns for
N = 4, 8, and 16.


Here is my program:
public class ThueMorse 
{
    public static void drawThueMorse1(int n, double x, double y, double size)
    {
        if (n == 0) return;
        double x1 = x - size/2, x2 = x + size/2;
        double y1 = y - size/2, y2 = y + size/2;
        StdDraw.setPenColor(StdDraw.BOOK_BLUE);
        StdDraw.filledRectangle(x+(3*size/4),y,size/4,size/2);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x-(3*size/4),y,size/4,size/2);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x,y+(3*size/4),size/2,size/4);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x,y-(3*size/4),size/2,size/4);
        //StdDraw.pause(300);
        StdDraw.setPenColor(StdDraw.WHITE);
        StdDraw.filledSquare(x,y,size/2);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x+(3*size/4),y+(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x+(3*size/4),y-(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x-(3*size/4),y-(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x-(3*size/4),y+(3*size/4),size/4);
        //StdDraw.pause(300);
        drawThueMorse1(n-1, x1, y1, size/2);
        drawThueMorse2(n-1, x1, y2, size/2);
        drawThueMorse2(n-1, x2, y1, size/2);
        drawThueMorse1(n-1, x2, y2, size/2);
    }
    public static void drawThueMorse2(int n, double x, double y, double size)
    {
        if (n == 0) return;
        double x1 = x - size/2, x2 = x + size/2;
        double y1 = y - size/2, y2 = y + size/2;
        StdDraw.setPenColor(StdDraw.WHITE);
        StdDraw.filledRectangle(x+(3*size/4),y,size/4,size/2);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x-(3*size/4),y,size/4,size/2);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x,y+(3*size/4),size/2,size/4);
        //StdDraw.pause(300);
        StdDraw.filledRectangle(x,y-(3*size/4),size/2,size/4);
        //StdDraw.pause(300);
        StdDraw.setPenColor(StdDraw.BOOK_BLUE);
        StdDraw.filledSquare(x,y,size/2);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x+(3*size/4),y+(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x+(3*size/4),y-(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x-(3*size/4),y-(3*size/4),size/4);
        //StdDraw.pause(300);
        StdDraw.filledSquare(x-(3*size/4),y+(3*size/4),size/4);
        //StdDraw.pause(300);
        drawThueMorse1(n-1, x1, y1, size/2);
        drawThueMorse2(n-1, x1, y2, size/2);
        drawThueMorse2(n-1, x2, y1, size/2);
        drawThueMorse1(n-1, x2, y2, size/2);
    }
    public static int log2(int x)
    {
        return (int) (Math.log(x)/Math.log(2));
    }
    public static void main(String[] args)
    {   
        int n = Integer.parseInt(args[0]);
        n = log2(n)-1;
        drawThueMorse1(n, 0.5, 0.5, 0.5);
    }
}

StdDraw is a simple API written by the authors of the book. I checked my program and it works. Here is one instance of it:
Input: N = 256
Output:

Is there any way that I can improve my program?
Thanks for your attention.
Is there any way that I can improve my program?

Yes :)
A good cue to see if your program can be improved is when there is lot of repetition in the code. There are usually ways to avoid repetition, although they can sometimes get pretty complex. However, avoiding repetition is useful for two very important reasons :

Copy/paste usually leads to &quot;dumb&quot; bugs
If you want to change a thing you need to change it in a billion places, making it more likely you'll forget one.

I'll be very honest, I'm reading your code as much as I can, but I don't understand what's happening in there, so it's going to be hard to provide a review of what you're doing, but it's also an indication that the code isn't clear enough to be understood by someone trying to understand it (me, in this case).
What can be done about this?

Use comprehensive names (That goes for methods, variables, everything really)
Spacing the code properly (Have you ever read a complicated paper/book where all the text was cramped up? Have you ever read another one where the was good spacing? It makes a world of difference!)
Avoiding commented code (Why is it there? Is it a mistake? Should it be uncommented? How long has it been commented? Why?)
Finally, when none of those tips are enough, you should comment your code, but be cautious not to &quot;overcomment&quot;. Comments should be just long enough so that someone can understand why you coded the way you did. There's no need to explain things such as &quot;I'm changing the pen color&quot; over StdDraw.setPenColor(StdDraw.BOOK_BLUE);

Now, there's one thing that I think would help tremedously with the readability of the code. Right now, your code both computes the &quot;pattern&quot; and prints it. What if you first generated a binary 2D array that fit the problem at hand, and you had another function that printed this array?
Taking an example of the N=4 case you gave, the array could look like this :
0110
1001
1001
0110

Separating the algorithm from the printing will also let you see how you can improve your code.
For example, we can notice that there's symmetry between the \$row_i\$ and \$col_i\$, meaning that we only need to find the value of half the grid in order to find all the values (that would be a valuable optimisation for a problem with a big N value).
Now, if I take a look at the link you gave us, I see that :

Amazingly, the Thue-Morse sequence can be generated from the substitution system :
0 -&gt; 01 and 1 -&gt; 10, recursively.

Let's look at this with the first row of the N=8 example you gave us. We'll need  \$log_2(8)=3\$ iterations of this substitution sequence : 0-&gt;01-&gt;0110-&gt;01101001. Let's fill our 2D array with this :
0 1 1 0 1 0 0 1
1 X X X X X X X
1 X X X X X X X
0 X X X X X X X
1 X X X X X X X
0 X X X X X X X
0 X X X X X X X
1 X X X X X X X

Now, let's fill the second row, knowing that the first value is 1 : 1 -&gt; 10 -&gt; 1001 -&gt; 10010110
0 1 1 0 1 0 0 1
1 0 0 1 0 1 1 0
1 0 X X X X X X
0 1 X X X X X X
1 0 X X X X X X
0 1 X X X X X X
0 1 X X X X X X
1 0 X X X X X X

For completion, let's do the third row, and I'll leave the rest to you 10 -&gt; 1001 -&gt; 10010110
0 1 1 0 1 0 0 1
1 0 0 1 0 1 1 0
1 0 0 1 0 1 1 0
0 1 1 X X X X X
1 0 0 X X X X X
0 1 1 X X X X X
0 1 1 X X X X X
1 0 0 X X X X X

I guess you see where this ends. This leads to a pretty performant approach with code that should be pretty simple to understand. Afterwards, you could have a function paintThueMorse, give it this 2D array and paint blue for 1, white for 0 or the inverse.