title: Recursive changing variables - Sierpinski carpet
body: <p>I'm having some problems whit drawing a sierpinski carpet, and would apreciate any help. </p>
  
  <p>I was able to define the stoping condition, draw the central rectangle, and recursively, draw the next level of the image, all while keeping count. </p>
  
  <p>It just so happens that I can only draw on the top left side. I'd say I'm confusing variables, but I can't seem to figure it out. Would apreciate any help</p>
  
  <p>This is the part of the code where i'm having problems.</p>
  
  <pre><code>    int smallerWidth = newWidth / 3;
      int smallerHeight = newHeight / 3;
  
      int sX = 0;
      int sY = 0;
      if (currentDeep &gt; 1) {
          for (int i = 0; i &lt; 3; i++) {
              sX = width / 9 + (i * 3 * (width / 9));
              sY = height / 9;
              g.fillRect(sX, sY, smallerWidth, smallerHeight);
              for (int j = 0; j &lt; 3; j++) {
                  sY = height / 9 + (j * 3 * (height / 9));
                  g.fillRect(sX, sY, smallerWidth, smallerHeight);
              }
          }
          return 1 + printSquares(g, sX, sY, newWidth, newHeight, currentDeep 
                                                    - 1);
      } else
          return 1;
  }
  </code></pre>
  
  <p>This is the full code
  <a href="https://pastebin.com/WPJ5tG8w" rel="nofollow noreferrer">https://pastebin.com/WPJ5tG8w</a></p>
  
  <p>In sum my question is. What should I change/create in order for my program to draw the remaining 7 squares?</p>