We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Help with simple recursion
Page Index Toggle Pages: 1
Help with simple recursion (Read 1256 times)
Help with simple recursion
Mar 29th, 2010, 9:38pm
 
Hello,

I am working on a simple recursion assignment, here is my code thus far:

void setup (){
 size(480, 480);
 smooth();
 noStroke();
 fill(0);
 background(200, 0, 200);
}

void draw(){
 squares(320, 160, 160);
}

void squares(float xStart, float yStart, float sqScale) {
 float botmY = yStart*2.3333333;

 if(sqScale >= 5) {

   rect(xStart, yStart, sqScale, sqScale);//R
   rect(xStart-sqScale, yStart+sqScale, sqScale, sqScale);//T
   rect(xStart-sqScale, yStart-sqScale, sqScale, sqScale);//B
   rect(xStart-xStart, yStart, sqScale, sqScale);//L

   squares(xStart/3, yStart/3, sqScale/3);
   squares(xStart/3,botmY,sqScale/3);

 }
}

---

I want all of the groupings of squares on the left side to resemble the top left (recursion down to 5X5).  I am stuck on the "bottom branch" of the recursion, I've tried tweaking the code many ways with no luck.  I think I've been staring at this one too long so some fresh eyes and any advice would be greatly appreciated.  First forum post too fyi. Thanks.



Re: Help with simple recursion
Reply #1 - Mar 30th, 2010, 3:30pm
 
Hey,
I would rethink the function this way, in pseudocode:

1. draw the grid of 9 squares (by drawing 5 or 4 squares, really)
2. call squares() at the left-hand 3 locations, if sqScale is large enough
Page Index Toggle Pages: 1