xxxxxxxxxx
48
let r, g, b, x, y, xspeed, yspeed;
let animate = false;
const radius = 25;
function setup() {
createCanvas(windowWidth, windowHeight);
x = width / 2;
y = height / 2;
xspeed = random(3, 7);
yspeed = random(3, 7);
r = 0;
g = 0;
b = 0;
}
function mousePressed() {
animate = !animate
}
function draw() {
background(0);
noStroke();
fill(r, g, b);
circle(x, y, radius * 2);
if (animate) {
x += xspeed;
y += yspeed;
}
if (x <= radius || x >= width - radius) {
xspeed = xspeed * -1;
r = random(255);
g = random(255);
b = random(255);
}
if (y <= radius || y >= height - radius) {
yspeed = yspeed * -1;
r = random(255);
g = random(255);
b = random(255);
}
}