xxxxxxxxxx
43
let ball = {
x: 50,
y: 50,
xspeed:4,
yspeed:6,
}
let square = {
x: 50,
y: 50,
xspeed:4,
yspeed:6,
}
function setup() {
createCanvas(windowWidth, windowHeight);
square.x = random(width);
square.y = random(height);
square.xspeed =
}
function draw() {
background(220);
fill(300, ball.x, ball.y);
ellipse(ball.x, ball.y, 100, 100);
fill(0,0,225)
rect(square.x, square.y, 60, 60);
// move on y axis and change to negative to go backward
if(ball.x > windowWidth || ball.x <= 0) {
ball.xspeed = ball.xspeed * -1;
}
if(ball.y > windowHeight || ball.y <= 0) {
ball.yspeed = ball.yspeed * -1;
}
ball.x= ball.x + ball.xspeed; // changes x position randomly
ball.y= ball.y + ball.yspeed; // changes y position randomly
//console.log(x)
}