createCanvas(size, size, WEBGL);
clock = new PeriodicFrameClock(sketch.fpp());
c1 = color([12, 100, 100]);
c2 = color([102, 100, 100]);
c3 = color([192, 100, 100]);
c4 = color([282, 100, 100]);
const hexagonRadius = radius / 4;
const numberOfPoints = 240;
for (let i = 0; i < numberOfPoints; i++) {
const p = i / numberOfPoints;
const x = -radius * cos(theta) * clock.sin(t);
const y = radius * sin(theta);
const z = radius * cos(theta) * clock.cos(t);
function drawHexagon(x, y, z, p) {
const r = hexagonRadius / (1 + 0.01 * z);
const rp = ease(map(r, hexagonRadius, 2.01 * hexagonRadius, 0, 1));
const rotation = -TAU * p;
for (let i = 0; i <= TAU; i += TAU / 6) {
const theta = i + rotation;
const color = getColor(p, rp);
vertex(r * cos(theta), r * sin(theta));
return 3 * pow(p, 2) - 2 * pow(p, 3);
function getColor(p, rp) {
c = lerpColor(c1, c2, map(p, 0, 0.25, 0, 1));
c = lerpColor(c2, c3, map(p, 0.25, 0.45, 0, 1));
c = lerpColor(c3, c4, map(p, 0.45, 0.75, 0, 1));
c = lerpColor(c4, c1, map(p, 0.75, 1.0, 0, 1));
const b = map(rp, 0, 1, 0.85, 1) * brightness(c);
const a = map(rp, 0, 1, 0.5, 0.08);