# Iterating a variable within a recursive drawing

**URL:** <https://discourse.processing.org/t/iterating-a-variable-within-a-recursive-drawing/321>\
**Category:** Coding Questions\
**Created:** [May 24, 2018, 1:39am UTC](https://discourse.processing.org/t/iterating-a-variable-within-a-recursive-drawing/321 "2018-05-24T01:39:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Focksbot](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Focksbot](https://discourse.processing.org/u/Focksbot)\
**Post date:** [May 24, 2018, 1:39am UTC](https://discourse.processing.org/t/iterating-a-variable-within-a-recursive-drawing/321/1 "2018-05-24T01:39:07Z")

</div>

Hi! I’m playing around with the code for Casey Reas’ Repeat: Recursion Tree ( [http://formandcode.com/code-examples/repeat-recursive-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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [May 24, 2018, 9:47pm UTC](https://discourse.processing.org/t/iterating-a-variable-within-a-recursive-drawing/321/2 "2018-05-24T21:47:43Z")

</div>

Can you please post a [MCVE](https://stackoverflow.com/help/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](http://happycoding.io/tutorials/processing/debugging) to see which line of code is behaving differently from what you expected?

---

<div class="post-metadata">

**Author:** ![Focksbot](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Focksbot](https://discourse.processing.org/u/Focksbot)\
**Post date:** [May 29, 2018, 12:42am UTC](https://discourse.processing.org/t/iterating-a-variable-within-a-recursive-drawing/321/3 "2018-05-29T00:42:35Z")

</div>

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.
