xxxxxxxxxx
41
var ball = {
x: 300,
y: 200,
xSpeed: 4,
ySpeed: 4,
radius: 25
}
let canW = 400;
let canH = 400;
function setup() {
createCanvas(canW,canH);
}
function draw() {
background(250);
displayFrame();
move();
bounce();
}
function displayFrame() {
strokeWeight(0);
fill(100,150,255);
circle(ball.x,ball.y,ball.radius);
}
function move() {
ball.x += ball.xSpeed;
ball.y += ball.ySpeed;
}
function bounce(){
if(ball.x >= canW - ball.radius /2 || ball.x <= 0) {
ball.xSpeed *= -1;
}
if(ball.y >= canH - ball.radius/2 || ball.y <= 0) {
ball.ySpeed *= -1;
}
}