xxxxxxxxxx
39
var ball = {
x : 300,
y : 200,
xspeed : 4,
yspeed : -5
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
move();
bounce();
display();
}
function move(){
ball.y = ball.y + ball.yspeed;
ball.x = ball.x + ball.xspeed;
}
function bounce(){
if (ball.x>width || ball.x<0){
ball.xspeed = ball.xspeed*-1;
}
if (ball.y>height || ball.y<0){
ball.yspeed = ball.yspeed*-1;
}
}
function display(){
ellipse(ball.x,ball.y,20,20);
}