I am rotating small evenly spaced circles around the circumference of a larger circle.
Using the while loop I have a version with 4 small circles and a version with 6 small circles.
The 4 small circles version places the circles at: 45°, 135°, 225° and 315°.
How do I adjust the code (below) so that the 4 circles appear at: 0, 90, 180 and 270?
void setup() {
size(400, 400);
background(255);
}
void draw() {
fill(255);
ellipse (width/2, height/2, 50, 50);
translate (width/2, height/2);
fill(0);
float c = 0;
//4 small cirlces evenly spaced around
//circumference of larger circle at
//90 degree intervals
while (c < 360/90) {
rotate (radians(90));
ellipse (20, 20, 20, 20);
c = c +1;
}
}
Also showing the 6 circle version as another example of how do I adjust so that circles appear at: 0, 60, 120, etc?
void setup() {
size(400, 400);
background(255);
}
void draw() {
fill(255);
ellipse (width/2, height/2, 50, 50);
translate (width/2, height/2);
fill(0);
float c = 0;
//6 small cirlces evenly spaced around
//circumference of larger circle at
//60 degree intervals
while (c < 360/60) {
rotate (radians(60));
ellipse (20, 20, 20, 20);
c = c +1;
}
}
It’s probably something very simple but I’ve not yet been able to find any documentation to address this.
Thank you to anyone who can help.
I have been trying different numbers.
But isn’t: while (c < 360/90) just the counter?
I want the position of the 4 circles to move 45 degrees to the right along the circumference path so that the circles appear 1 at top, 1 bottom, 1 left side, 1 right side
I looked into this and I understand the confusion:
first off, 0 degrees is on the right side of the big circle (clock: 3 o’clock), not at the top as we would expect
2nd, we rotate 90 degrees before drawing the first small circle. So first small circle is even at 6 o’clock now.
3rd: problem is that the ellipse is drawn at (relative) position 20,20: ellipse (20, 20, 20, 20);. This means, it’s off in X and Y direction, which is even more confusing (made it look like an additional rotation by 45 degrees I guess).
Here is a sketch that solves this by printing **c** at the sides (so we know which ellipse is drawn first. It’s a neat trick to find out what is going on to use text() sometimes) and a few other things (what I just mentioned):
put 0 degree at 12 o’clock (instead of 3) by rotation -90 degree (rotate left) before the while-loop
inside the while loop we first draw the ellipse and then rotate after that (at the end of the while loop), so the first (0th) small circle is really at the top.
we say ellipse (20, 0, 20, 20); so x-position = 20 (gives you the radius), relative y-position = 0. This means we move 20 towards x every time (which does not add up), because of rotate this is first time: north (12 o’clock), then east (3 o’clock) then south (6) and then west (9)
void setup() {
size(400, 400);
background(255);
}
void draw() {
fill(255);
ellipse (width/2, height/2, 50, 50);
translate (width/2, height/2);
fill(0);
float c = 0;
//4 small cirlces evenly spaced around
//circumference of larger circle at
//90 degree intervals
rotate (-radians(90)); // !!!!!!!!!!!!!!! put 0 degree at 12 o'clock (instead of 3)
float angleStep = 90;
while (c < 360/angleStep) {
ellipse (20, 0, 20, 20); // draw BEFORE rotate; relative y-position = 0
text(c, 30, 20);
rotate (radians(angleStep));
c = c + 1;
}
noLoop();
}