Recursive function to create circles getting smaller(NEW ISSUE PLEASE READ)
in
Programming Questions
•
8 months ago
Okay so I have some code that I *THINK* should work, do not bash me if it's miles off but it's getting too much recursion error. Could anyone hint me toward what it looks like i've cocked up on?
- void setup(){
- size(500,500);
- }
- void circles(int x, int y, int radius, int numb){
- int L=1;
- ellipse(x,y,radius,radius);
- if(numb>1){
- if(L==1){
- circles(x,y-radius/4,radius/2,numb);
- L++;
- }
- if(L==2){
- circles(x+radius/4,y,radius/2,numb);
- L++;
- }
- if(L==3){
- circles(x,y+radius/4,radius/2,numb);
- L++;
- }
- if(L==4){
- circles(x-radius/8,y,radius/2,numb);
- L = 1;
- }
- numb=numb-1;
- }
- }
- void draw(){
- circles(250,250,250,2);
- }
So I've been set an assignment to write a recursive function to produce the following:
- size(200,200);
- int xpos = width/2;
- int ypos = height/2;
- int x = width;
- int y = height;
- ellipse(xpos,ypos,x,y);
- ellipse(xpos,4*ypos/8,x/2,y/2);
- ellipse(20*xpos/16,4*ypos/8,x/4,y/4);
- ellipse(20*xpos/16,5*ypos/8,x/8,y/8);
- ellipse(19*xpos/16,5*ypos/8,x/16,y/16);
So I understand how to use recursion, I had another task to do in which I created a fibonacci number generator using recursion. However I'm entirely stumped on how this is supposed to work with recursion. So I'm not asking for the answer I'm asking for a nudge in the right direction, if possible, as i've spent many hours contemplating about how to utilize recursion for this task...
Thanks in advanced!
edit:
latest development is:
- void setup(){
- size(500,500);
- }
- void circles(int y, int radius, int numb){
- float tt = 126*numb/4.0;
- fill(tt);
- ellipse(width/2,y,radius,radius);
- if(numb>1){
- numb--;
- circles(y-radius/4,radius/2,numb);
- }
- }
- void draw(){
- circles(width/2,width,5);
- }
1