xxxxxxxxxx
34
const radius = 20
const speed = 2
let dirx = 1
let diry = 1
let posx;
let posy;
function setup() {
createCanvas(600, 600);
posx = width/3
posy = height/2
}
function draw() {
if (posx >= width - radius/2 || posx === radius/2){
dirx = -1*dirx
}
if (posy >= height - radius/2 || posy === radius/2){
diry = -1*diry
}
background(120) // apagar as coia anteriro desenhada na tela
posx = posx + speed * dirx
posy = posy + speed * diry
ellipse(posx, posy, radius, radius);
}