Ok, here's my problem.
If I have a code like this one..
But let's say I have a code like this one..
I understand that this is so because draw() function calls the drrr() function which calls itself, which then calls itself etc. and only when the recursion is over, the draw function finaly makes a loop and updates itself and draws the picture.
I'm looking for a way of drawing the steps of the recursion separately, each level of branches in a different frame and I have no idea how to even start programing something like that.
The reason I'm asking you how to do this is because I'd like to draw something like the lines in the first of two codes I posted above in order to simulate the growth of mycelium. My idea is to draw a line which will then (at the moment I will define as I want) split into few branches which would then act in the same way as other branches and this deffinitely has something to do with recursion and I'd like to learn more about thinking in that way.
Thanks in advance.
If I have a code like this one..
- float x, y, px, py, kut, nz;
- void setup() {
- size(600, 400);
- background(255);
- stroke(0);
- smooth();
- px = width/2;
- py = height/2;
- }
- void draw() {
- kut = 720*noise(nz);
- x = px + 10*cos(radians(kut));
- y = py + 10*sin(radians(kut));
- line(px, py, x, y);
- px = x;
- py = y;
- nz += 0.1;
- }
But let's say I have a code like this one..
- float x, y;
- void setup() {
- size(600, 400);
- background(255);
- stroke(0);
- smooth();
- x = 40;
- y = height/2;
- }
- void draw() {
- drrr(x, y, x + 230, y+113, 3);
- drrr(x, y, x + 230, y-113, 3);
- }
- void drrr(float x1, float y1, float x2, float y2, int i) {
- if (i>0) {
- drrr(x2, y2, x2 + 230*i/15, y2 + 113*i/15, i-1);
- drrr(x2, y2, x2 + 230*i/15, y2 - 113*i/15, i-1);
- }
- line(x1, y1, x2, y2);
- }
I understand that this is so because draw() function calls the drrr() function which calls itself, which then calls itself etc. and only when the recursion is over, the draw function finaly makes a loop and updates itself and draws the picture.
I'm looking for a way of drawing the steps of the recursion separately, each level of branches in a different frame and I have no idea how to even start programing something like that.
The reason I'm asking you how to do this is because I'd like to draw something like the lines in the first of two codes I posted above in order to simulate the growth of mycelium. My idea is to draw a line which will then (at the moment I will define as I want) split into few branches which would then act in the same way as other branches and this deffinitely has something to do with recursion and I'd like to learn more about thinking in that way.
Thanks in advance.
1