xxxxxxxxxx
24
function setup() {
createCanvas(150, 150);
background(240);
}
let x = 10;
let y = 75;
let xDir = 3;
let yDir = 3;
function draw() {
background(240);
ellipse(x, y, 20);
x = x + xDir;
y = y + yDir;
if ((x > width-10) || (x < 10)) {
//print("we are on the canvas")
//print("we are off the canvas")
xDir = xDir*(-1);
}
if ((y > height-10) || (y < 10) ){
yDir = yDir*(-1)
}
}