xxxxxxxxxx
56
var ball = {
x: 50,
y: 50,
h: 20,
vx: 0,
vy: 0
};
var backCol ={
r: 0,
g: 0,
b: 0
};
function setup() {
createCanvas(600, 600);
ball.vy = random(4, 6);
ball.vx = random(3, 5);
}
function draw() {
background(backCol.r, backCol.g, backCol.r);
display();
bounce();
move();
}
function display(){
noStroke();
fill(255);
ellipse(ball.x, ball.y, ball.h);
}
function mousePressed(){
backCol.r = random(150, 255);
backCol.g = random(50, 150);
backCol.b = random(100, 200);
}
function bounce(){
if(ball.y > height || ball.y < 0){
ball.vy = -ball.vy;
ball.h = random(10, 40);
}
if(ball.x > width || ball.x < 0){
ball.vx = -ball.vx;
ball.h = random(10, 40);
}
}
function move(){
ball.y += ball.vy;
ball.x += ball.vx;
}