Do you want to improve this question?Edit this post and update the question to focus on one issue
Closed 6 years ago.
6 years agointleftCenterX=150;
interruptRad=100;
int satelliteDia=30;
int X = leftCenterX, Y = 240;
intangle = 0;
int speed = 1;
void draw() {
background(255);
fill(255,255,255);
stroke(0);
ellipse (leftCenterX, Y, orbitRad*2, orbitRad*2);
ellipse (leftCenterX+orbitRad*2, Y,orbitRad*2,orbitRad*2);
fill(0,0,255);
noStroke();
if(angle>=360){
println("left_to_right");
speed = - speed;
angle = 180;
X=leftCenterX+orbitRad*2;
}
if(angle<=-180){
println("right_to_left");
speed = - speed;
angle = 0;
X = leftCenterX;
}
else(cos(radians(angle))*orbitRad+X,
sin(radians(angle))*orbitRad+Y,
satelliteDia, satelliteDia);
angle=angle+speed;
}
I understand the meaning of the word in this code, but when I look at it in general, I don't know where it is linked.When I preview this, the blue dots move over the two circles, but I don't know why they pass over the two circles.
I look forward to your kind cooperation.
I didn't know the point of the question, I didn't know the execution environment, so I couldn't move it, but I'll explain the behavior a little bit as if I were looking at the code.
If you run it, you will probably draw two white circles on the left and right sides and a blue circle along the circle.The blue circle moves along the white circle on the left, and then along the white circle on the right.
The white circle is drawn in a fixed position every time, and the blue circle is just calculated and drawn along the white circle.
One axis of this process is "angle," which starts with zero and increases by one to 360.During this time, move along the white circle on the left.If it is over 360, the angle will be set to 180 and this time it will decrease by 1 from 180 to -180.During this period, it moves along the right-hand circle.Similarly, once you go around, the angle resets to 0 and returns to its initial state (and starts moving along the left circle).
With the two "if" statements, it is determined whether one lap has been made and processed to move (looks like) to the next circle.We use sin/cos for the coordinate calculation of "move along the circle".The changeover of the right circle to the left depends on the "X" variable.
© 2024 OneMinuteCode. All rights reserved.