xxxxxxxxxx
41
let x = 200;
let y = 200;
let xspeed = 1;
let ballColor;
let ballSize = 10;
function setup() {
createCanvas(400, 400);
// Start color: White
ballColor = color(255);
}
function draw() {
background(0);
// ball color change
fill(ballColor);
// Ball
circle(x, y, ballSize);
// Ball movement
x = x + xspeed;
// Ball bounces off the right side
if (x > width) {
xspeed = -random(1, 5); // Random speed on bounce
ballColor = color(random(255), random(255), random(255));
// Change color
ballSize = random(10, 30);
// Change size
}
// Ball bounces off the left side
if (x < 0) {
xspeed = random(1, 5); // Random speed on bounce
ballColor = color(random(255), random(255), random(255)); // Change color
ballSize = random(10, 30); // Change size
}
}