xxxxxxxxxx
let speedx;
let speedy;
let rad = 25;
function setup() {
createCanvas(400, 600);
x = width/2;
y = height/2;
speedx = 4;
speedy = 4;
}
function draw() {
background(0);
fill(255);
square(0, 0, 100);
square(0, 100, 100);
square(0, 200, 100);
square(0, 300, 100);
square(0, 400, 100);
square(0, 500, 100);
noFill();
print("Move your mouse up and down the boxes on the left to make a ball appear and choose its colour");
if(mouseY < 100 && mouseX < 100){
fill(204, 0, 0);
rect(0, 0, 100, 100);
}
else if(mouseY > 100 && mouseY < 200 && mouseX < 100){
fill(0, 0, 153);
rect(0, 100, 100, 100);
}
else if(mouseY > 200 && mouseY < 300 && mouseX < 100){
fill(0, 102, 0);
rect(0, 200, 100, 100);
}
else if(mouseY > 300 && mouseY < 400 && mouseX < 100){
fill(51, 255, 255);
rect(0, 300, 100, 100);
}
else if(mouseY > 400 && mouseY < 500 && mouseX < 100){
fill(255, 0, 255);
rect(0, 400, 100, 100);
}
else if(mouseY > 500 && mouseY < 600 && mouseX < 100){
fill(255, 255, 0);
rect(0, 500, 100, 100);
}
ellipse(x, y, rad*2, rad*2);
x += speedx;
y += speedy;
if(x < 100 + rad || x > width - rad ){
speedx = speedx * -1;
}
if(y < 0 + rad || y > height - rad){
speedy = speedy * -1;
}
}