Hi everyone! I have come across what I think may be a bug. I am just testing a recursive function which:
- Draws 6 circles around a circle
- for each circle, draw 6 circles around it.
This is the following code I wrote. (Counter was for debugging).
var r;
var counter;
function setup() {
createCanvas(windowWidth,windowHeight);
r = height/10;
counter = 1;
}
function draw() {
background(255);
push();
translate(width/2,height/2);
noFill();
rotate(millis()/1000);
circle(0,0,r);
circleAround(0,0,r,2);
pop();
}
function circleAround(x,y,r,levels){
let numSides = 6;
for(i=0;i<360;i+=360/6){
counter++;
//console.log(counter);
let circleX = r * cos(radians(i));
let circleY = r * sin(radians(i));
push()
noFill();
translate(circleX,circleY);
if(levels>0){
circleAround(0,0,r,levels-1);
}
circle(0,0,r);
pop();
}
}
This produces this output.
I found this strange and rewrote the code in Processing. In Processing, the code produced the correct output. (I can’t post a second screenshot since I am a new user)
Is there a mistake in my Javascript? Thank you!