We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi Coders!
I want to arrange many lines around a circle in Processing. The amount of lines shall be controlled by the mouseX-position. But i struggle with that:
I want the lines to be arranged around the circle properly. The angle/gap between the lines shall be equal. But there's a gap between the first and the last line.
I try to get familiar with the map()-function but it does not work.
Thank you guys!!!!
Here's my code:
int a;
void setup () {
size(540, 540);
background(#222222);
stroke(#dddddd);
noFill();
}
void draw() {
a = mouseX;
map(a,0,width,0,100);
background(#222222);
translate(width/2, height/2);
ellipse(0,0,100,100);
for (int i = 0; i < a; i++) {
rotate(radians(360/a));
line(50, 0, 200, 0);
}
println(a);
}
Answers
Two problems here.
Problem 1: line 11 is wasted because you can use mouseX directly so delete it.
Problem 2: the line 12 does NOT modify the variable
a
rather it returns a floating point number which must be assigned to a variable. So change line 12 toa = int(map(mouseX,0,width,0,100));
Problem 3: In line 17
360/a
does an integer division so when a = 100 it returns 3 not 3.6 change this line torotate(radians(360.0/a));
because 360.0 is a float it will force a floating point division.
Beautiful! Works perfect! Thanx!
@quark said:
Or instead of converting 360 to radians why not just apply the calculation to the radians equivalent directly: TWO_PI
The definition in the reference is a little too technical for my liking and could make it clearer that it's equivalent to 360 degrees ;)
or with sin cos