bnb({
w: 540,
h: 540,
numFrames: 180,
fps: 30,
setup: (s, g) => {
g.shapes = [];
const center = s.createVector(s.width / 2, s.height / 2);
for (let i = 19; i > 0; i--) {
g.shapes.push(new Hexagon(s, center, 30 + i * 12));
}
},
draw: (s, t, g) => {
s.background("black");
g.shapes.forEach((hex, idx) => {
const curr = Math.floor(t * 18);
const tt = (t - curr / 18) * 18;
for (let i = 0; i < hex.vertices.length; i++) {
const v1 = hex.vertices[i];
const v2 = hex.vertices[(i + 1) % hex.vertices.length];
let animate = 0;
if (curr == i) {
animate = animationFn(tt);
} else if (curr > 11 && curr % 6 == i) {
animate = 1 - animationFn(tt);
} else if ((curr < 6 && curr < i) || (curr > 11 && curr % 6 > i)) {
animate = 0;
} else {
animate = 1;
}
const lineColor = colorFn((t * 2 + idx / 10) % 1);
s.stroke(lineColor);
s.strokeWeight(animate ? 12 : 0);
if (curr < 6) {
s.line(
v1.x,
v1.y,
lerp(v1.x, v2.x, animate),
lerp(v1.y, v2.y, animate)
);
} else {
s.line(
lerp(v2.x, v1.x, animate),
lerp(v2.y, v1.y, animate),
v2.x,
v2.y
);
}
}
});
}
})