xxxxxxxxxx
42
var ball = {
x: 0,
y: 0,
width: 50,
height: 50,
speedX: 3,
speedY: -5
}
var speed = 3;
var colorR = {
r: 0,
b: 0,
g: 0
};
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
ellipse(ball.x, ball.y, ball.width, ball.height);
if (ball.x > width || ball.x < 0) {
ball.speedX *= -1;
}
if(ball.y > height || ball.y < 0) {
ball.speedY *= -1;
}
ball.x += ball.speedX;
ball.y += ball.speedY;
}
function mousePressed() {
colorR.r = floor(random(100, 255));
colorR.b = floor(random(100, 255));
colorR.g = floor(random(100, 255));
if (mouseX > (ball.x - ball.width/2) && mouseX < (ball.x + ball.width/2) && mouseX > (ball.y - ball.height/2) && mouseY < ball.y + ball.height/2) {
fill(colorR.r, colorR.b, colorR.g);
ellipse(ball.x, ball.y, 100, 100);
}
}