Hi guys,
Trying to alternate two ellipse from one end of canvas before getting to the middle, stopping one dead in its tracks, before initiating movement from the other in the opposite direction. They must move asynchronously.
Below is what i have so far, im trying to utilise booleans to my advantage but no luck:
const size = 600;
let yPos1, yPos2, oneQ, threeQ, target1,target2, towardsCenter;
//let ySpeed, angle;
function setup() {
createCanvas(size, size);
// Initializing the variables:
yPos1 = height - 100;
yPos2 = 100;
x2 = 400;
x = 200;
target2 = height / 2;
moving = true;
}
xSpeed = 5;
xSpeed2 = 5;
function draw() {
background(0, 15);
let oneC = ellipse(x, yPos2, 100, 100);
x = x + xSpeed;
let twoC = ellipse(x2, yPos1, 100, 100);
stopCircle(x, x2, oneC, twoC);
}
function stopCircle(xPos, xPos2, circ, circ2) {
if (moving){ // if left circle moving
if (xPos > width / 2 - 10 || xPos < 0 + 60){
moving = false;
xSpeed = xSpeed + 0;
} else { // if left circle not moving. now trying to stop second right-most circle, and move the first one across half canvas.
xSpeed2 = xSpeed2 * -1;
if (xPos2 < width / 2 || xPos2 > width - 60){
moving = true;
xSpeed2 = xSpeed2 + 0;
}
}
x2 = x2 - xSpeed2; // initiate right circle movement along x-axis towards center
}
here is the link: code
realise im way off but spending too long on it, and need a small nudge in the right direction. Thanks.