class Hexagon {
constructor(s, i) {
this.radius = 43.3 / 2;
this.i = i;
this.cols = Math.ceil(s.width / (this.radius * 2)) + 5;
this.colorInterpolator = d3.interpolateRgb(
"gray",
palette[this.i % palette.length]
);
}
display(s, t, g) {
const angle = s.TAU / 6;
const { radius } = this;
const { x, y } = getCenter(
Math.floor(this.i / this.cols) - 2,
(this.i % this.cols) - 1,
radius
);
s.push();
s.stroke("gray");
for (let a = 0; a < 6; a++) {
const angle = (s.TAU * a) / 6;
const lineLength = radius;
if (
a * 3 === Math.round(Math.random() * 18) &&
lineLength >= radius &&
t < 0.6 &&
t > 0.4
) {
continue;
}
const animate = ease(linearstepUpDown(t, 0.1, 0.3, 0.7, 0.9), 2);
s.strokeWeight(animate + 1);
const animateColor = ease(linearstepUpDown(t, 0.3, 0.4, 0.6, 0.7), 2);
s.stroke(this.colorInterpolator(animateColor));
const sx = x + s.cos(angle * animate) * lineLength;
const sy = y + s.sin(angle * animate) * lineLength;
s.line(x, y, sx, sy);
}
s.pop();
}
}