xxxxxxxxxx
81
let x1; let y1;
let x2; let y2;
let x3; let y3;
let x4; let y4;
let a1; let b1;
let a2; let b2;
let a3; let b3;
let a4; let b4;
let s; // Speed
let d; // Direction
let dia;
function setup() {
createCanvas(800, 800);
x1 = width / 2; y1 = height / 2;
x2 = width / 2; y2 = height / 2;
x3 = width / 2; y3 = height / 2;
x4 = width / 2; y4 = height / 2;
a1 = width*0; b1 = height*0;
a2 = width; b2 = height*0;
a3 = width*0; b3 = height;
a4 = width; b4 = height;
dia = 80;
s = .5;
d = 1;
// d = (+) = right/ bottom; d = (-) = left/ top
}
function draw() {
background(10);
noStroke();
circle(x1, y1, dia);
circle(x2, y2, dia);
circle(x3, y3, dia);
circle(x4, y4, dia);
if(millis() > 1000){
x1 = x1 + s*d;
x2 = x2 + s*-d;
y3 = y3 + s*d;
y4 = y4 + s*-d;
}
circle(a1, b1, dia);
circle(a2, b2, dia);
circle(a3, b3, dia);
circle(a4, b4, dia);
if(x1 > width*0.6){
a1 = a1 + s*d;
b1 = b1 + s*d;
a2 = a2 + s*-d;
b2 = b2 + s*d;
a3 = a3 + s*d;
b3 = b3 + s*-d;
a4 = a4 + s*-d;
b4 = b4 + s*-d;
}
}