xxxxxxxxxx
50
let x;
let y;
let d; // direction x
let c; // colour
let r; // radius
let b; // background
let h; // direction y
function setup() {
createCanvas(400, 800);
x = 30
y = 200
d = +10
c = -255
r = 30
b = 200
h = +3
}
function draw() {
background(0, b ,b);
noStroke()
fill(c)
circle(x, y, r*2);
if (x > r-1 && x < width-r) {
c = c;
d = d;
}
else {
c = -c;
d = -d;
}
if (y > r-1 && y < height-r) {
h = h;
c = c;
}
else {
h = -h
c = -c;
}
x = x+d
y = y+h
}