Mouse help
in
Programming Questions
•
2 years ago
Hi -
Can someone please help me understand the behavior of the following sketch. It draws a curve, as expected, and one of the line segments moves with the mouse position, but (and this is what confuses me) none of the other line segments move. What I want is for the mouse position to control the rotation of the whole curve. What am I missing?
Thanks!
Leo
float nx; float ny; float mx; float my;
float px; float py; float x; float y;
float j; float sac;
void setup() {
size(480, 480);
smooth();
stroke(255);
}
void draw() {
background(0); // Set the background to black
mx=mouseX/width*3.14; my=mouseY/width*3.14;
px=mouseX; py=mouseY;
sac=6.28/(width/2);
for(j=0; j<6.28; j+=sac) {
x=cos(j); y=sin(j);
for(int i=1; i<4; i+=1){
nx = y * cos(3.14*x);
ny = y * sin(3.14*x);
x = nx*cos(mx)-ny*sin(mx);
y = ny*cos(mx)+nx*sin(mx);
}
line(x*width/2+width/2, y*width/2+width/2,px,py);
px=x*width/2+width/2; py=y*width/2+width/2;
}
}
1