xxxxxxxxxx
51
let rad = 100;
let xpos = 300;
let ypos = 500;
let speed = 5;
let xdirection = 1;
let ydirection = 1;
let circRed = 50;
let circGreen = 50;
let circBlue = 50;
function setup() {
createCanvas(800, 800);
}
function draw() {
background('black');
noStroke();
fill(circRed,circGreen,circBlue);
ellipse(xpos,ypos,rad*2,rad*2);
if (xpos >= width - rad || xpos <= rad) {
xdirection = xdirection * -1;
circRed = random(0,255);
circGreen = random(0,255);
circBlue = random(0,255);
}
if (ypos >= width - rad || ypos <= rad) {
ydirection = xdirection * -1;
circRed = random(0,255);
circGreen = random(0,255);
circBlue = random(0,255);
}
xpos = xpos + speed * xdirection;
ypos = ypos + speed * ydirection;
// print(xpos);
}