Iterating a variable within a recursive drawing

Hi! I’m playing around with the code for Casey Reas’ Repeat: Recursion Tree ( http://formandcode.com/code-examples/repeat-recursive-tree ).

I’d like to change it so that instead of there being a 2% chance of it creating branches, it checks the position in an array and bases the decision on that. So with every level of the recursion, I want it to move to the next position in the array.

This is how I’ve tried to do it:

void draw() {
  background(255);                  
  translate(width/2, height/2);         
  seed1(dotSize, radians(270), 0, 0, 0);  
  seed1(dotSize, radians(90), 0, 0, 0);
}

void seed1(float dotSize, float angle, float x, float y, int i) {
  
  if (dotSize > 1.0) {
    
   
    if (ffs[i]==true) {  
      ellipse(x, y, dotSize, dotSize);
      float newx = x + cos(angle) * dotSize;
      float newy = y + sin(angle) * dotSize;
      int newi = i + 1;
      seed1(dotSize * 0.99, angle - angleOffsetA, newx, newy, newi);   
    }

In practice, ‘i’ moves forward one position in the array, from 0 to 1, and then stays on 1 for every level of recursion onward.

Can anyone help me with how to get better results?

1 Like

Can you please post a MCVE? We can’t run your code because it’s missing variable declarations and has some missing curly brackets.

Why do you think the i parameter is staying at 1? Have you tried debugging your code to see which line of code is behaving differently from what you expected?

I’m afraid I’ve given up on this one and don’t have the code anymore. I think my lack of understanding is so fundamental that I need to start with something more basic.