Dueling Spheres
Play with purple and green in p5js.
let seedx = 1,
seedy = 1,
seedz = 1,
c = 0;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
angleMode(DEGREES);
background(126, 0, 255);
fill(128, 255, 0);
push();
translate(-width / 2, 0, 0);
plane(width);
pop();
}
function draw() {
pointLight(255, 255, 255, 0, 0, 3000);
pointLight(255, 255, 255, 0, 3000, 0);
pointLight(255, 255, 255, 3000, 0, 0);
fill(128, 255, 0);
t = frameCount * 3;
push();
if (c == 1) {
rotateX(t);
}
if (c == 2) {
rotateZ(t);
rotateX(t);
}
if (c == 3) {
rotateZ(-t / 6);
rotateX(-t);
}
if (c == 4) {
rotateZ(-t / 2);
rotateX(-t);
}
if (c == 5) {
rotateZ(-t);
rotateX(-t / 2);
}
push();
translate(seedx * sin(t), seedy * cos(t), seedz * cos(t));
seedx = seedx + 0.1;
seedy = seedy + 0.1;
seedz = seedz + 0.1;
sphere(20, 24, 24);
pop();
push();
fill(126, 0, 255);
translate(-seedx * sin(t), -seedy * cos(t), seedz * cos(t));
seedx = seedx + 0.1;
seedy = seedy + 0.1;
seedz = seedz + 0.1;
sphere(20, 24, 24);
pop();
pop();
if (t > 6000) {
background(126, 0, 255);
push();
translate(-width / 2, 0, 0);
plane(width);
pop();
frameCount = 0;
c = c + 1;
(seedx = 1), (seedy = 1), (seedz = 1);
if (c > 5) {
c = 0;
}
}
print(t);
}