xxxxxxxxxx
39
let circlePosX;
let circlePosY;
let speedX = 5;
let speedY = 7;
let circleRadius;
function setup() {
createCanvas(640, 640);
circleRadius = width / 16;
circlePosX = circleRadius;
circlePosY = circleRadius;
noStroke();
}
function draw() {
// EASY TRAILS
// instead of background
// draw a full screen rect (with no stroke)
// the color you want your background
// with some alpha value
fill(255, 25);
rect(0, 0, width, height);
fill(255, 120, 0, 200);
circle(circlePosX, circlePosY, circleRadius * 2);
circlePosX += speedX;
circlePosY += speedY;
// bounce the ball off walls with if statements with OR, which is two pipes: ||
if (circlePosX > width - circleRadius || circlePosX < circleRadius) {
speedX *= -1;
}
if (circlePosY > height - circleRadius || circlePosY < circleRadius) {
speedY *= -1;
}
}