let balls = [];
const numSpheres = 10;
const ringRadius = 150;
let t = 0;
let radius = 600;
function setup() {
createCanvas(720, 720, WEBGL);
for (let i = 0; i < numSpheres; i++) {
balls.push({
angle: (TWO_PI * i) / numSpheres
});
}
colorMode(RGB);
background(255);
}
function draw() {
t = frameCount / 40;
background(255);
ambientLight(50);
pointLight(
255,
255,
255,
radius * cos(-t / 1.5 + PI),
-600,
radius * sin(-t / 1.5 + PI)
);
push();
translate(0, 0, 0);
rotateX(HALF_PI);
fill(255, 179, 179);
noStroke();
plane(600, 600);
pop();
let camX = radius * cos(-t / 1.5 + PI);
let camZ = radius * sin(-t / 1.5 + PI);
let camY = -600;
camera(camX, camY, camZ, 0, 0, 0, 0, 1, 0);
for (let i = 0; i < balls.length; i++) {
let ball = balls[i];
ball.angle = (TWO_PI * i) / numSpheres + t;
let x = ringRadius * cos(ball.angle);
let z = ringRadius * sin(ball.angle);
let y = -sqrt(abs(x * x - z * z));
push();
translate(x, y, z);
fill(204, 51, 77);
noStroke();
sphere(20);
pop();
}
}