xxxxxxxxxx
37
var ball = {
x: 200,
y: 200,
xspeed: 5,
yspeed: -3
}
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
position();
bounce();
move();
}
function position() {
fill(86, 255, 138);
ellipse(ball.x, ball.y, 20);
}
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 move() {
ball.x += ball.xspeed;
ball.y += ball.yspeed;
}