Reputation: 11
i want to make my 2 circles move around my racetrack at different speeds using this method of coding, however both circles are acting upon 1 of the lines of code instead of independant of each other.
function setup() {
createCanvas(400, 400);
}
let angle =0;
function draw() {
background(0,255,0);
stroke(0);
fill(150);
ellipse(200, 200, 200, 100);
fill(0,255,0);
ellipse(200, 200, 125, 50);
noFill(0);
stroke(255,255,0);
ellipse(200, 200, 160, 70);
ellipse(200, 200, 165, 75);
//red circle
angleMode(DEGREES);
let centreX = width/2;
let centreY = height/2
let x = 85 * cos(angle);
let y = 47.5 * sin(angle);
fill(255,0,0);
ellipse(centreX + x, centreY + y, 10, 10);
angle += 1;
//blue circle
let centreA = width/2;
let centreB = height/2
let a = 65 * cos(angle);
let b = 30 * sin(angle);
fill(0,0,255);
ellipse(centreA + a, centreB + b, 10, 10);
angle += 2;
}
Both of the circles move on angle += 2 when i only want the blue circle to move at that speed and want the red one to remain at angle +=1. Any help is greatly appreciated! :)
Upvotes: 0
Views: 99
Reputation: 2052
You need them to be completely independent of each other. While most of your variables are independent, your angles are the same variable, meaning they're moving at the same angle += 1; angle += 2;
every time the code is run. To prevent that you need them to have 2 different angles.
Upvotes: 1