xxxxxxxxxx
86
let circleSize = 50;
let x1;
let x2;
let x3;
let x1speed = 2;
let x2speed = 3;
let x3speed = 5;
let y1;
let y2;
let y3;
let y1speed = 3;
let y2speed = 5;
let y3speed = 2;
function setup() {
createCanvas(400, 400);
x1 = width / 2;
x2 = random(width);
x3 = random(width/2);
y1 = height / 2;
y2 = random(height/2);
y3 = random(height);
}
function draw() {
background(220);
drawcircle1();
x1bounce();
y1bounce();
drawcircle2();
x2bounce();
y2bounce();
drawcircle3();
x3bounce();
y3bounce();
}
function drawcircle1() {
circle(x1, y1, circleSize);
x1 += x1speed;
y1 += y1speed;
}
function x1bounce(){
if (x1 > width || x1 < 0) {
x1speed *= -1;
}
}
function y1bounce(){
if (y1 > height || y1 < 0) {
y1speed *= -1;
}
}
function drawcircle2() {
circle(x2, y2, circleSize);
x2 += x2speed;
y2 += y2speed;
}
function x2bounce(){
if (x2 > width || x2 < 0) {
x2speed *= -1;
}
}
function y2bounce(){
if (y2 > height || y2 < 0) {
y2speed *= -1;
}
}
function drawcircle3() {
circle(x3, y3, circleSize);
x3 += x3speed;
y3 += y3speed;
}
function x3bounce(){
if (x3 > width || x3 < 0) {
x3speed *= -1;
}
}
function y3bounce(){
if (y3 > height || y3 < 0) {
y3speed *= -1;
}
}