xxxxxxxxxx
51
let x1,y1;
let x2,y2;
let x3,y3;
let x4,y4;
let x5,y5;
let x6,y6;
let x7,y7;
let x8,y8;
let w2h;
// Declare a variable for how fast the circle will travel horizontally.
let xspeed = 1;
// Declare and initialize a variable for how fast the circle will travel vertically.
let yspeed;
function setup() {
createCanvas(200, 400);
x1 = width/2; y1 = height/2;
x2 = width/2; y2 = height/2;
x3 = width/2; y3 = height/2;
x4 = width/2; y4 = height/2;
x5 = width/2; y5 = height/2;
x6 = width/2; y6 = height/2;
x7 = width/2; y7 = height/2;
x8 = width/2; y8 = height/2;
w2h = width/height;
yspeed = xspeed * w2h; // 1 * 2
}
function draw() {
background(220);
circle(x1,y1,20);
circle (x2,y2,20);
circle (x3,y3,20);
circle (x4,y4,20);
circle(x5, y5, 20);
circle(x6, y6, 20);
circle(x7, y7, 20);
circle(x8, y8, 20);
x1+=yspeed;
x2-=yspeed;
y3-=xspeed;
y4+=xspeed;
x5+=yspeed;y5+=xspeed;
x6-=yspeed;y6+=xspeed;
x7+=yspeed;y7-=xspeed;
x8-=yspeed;y8-=xspeed;
}