render_canvas_delay = () => {
const duration = .8;
const delay = (1 - duration) / 2 / (field_data.length + 1);
const ctx = DOM.context2d(w, h);
ctx.globalAlpha = 1;
ctx.fillStyle = backgroundColor;
ctx.lineWidth = line_width;
ctx.fillRect(0, 0, w, h);
return t => {
ctx.fillRect(0, 0, w, h);
ctx.beginPath();
ctx.strokeStyle = lineColor;
ctx.lineWidth = line_width;
field_data
.forEach((line, index) => {
const elapsed_time = t - index * delay;
const time_since_mid_point = t - .5 - index * delay;
let steps = d3.min([
Math.floor((elapsed_time / duration) * max_steps),
max_steps
]);
let start_step =
t > .5 ? Math.ceil((time_since_mid_point / duration) * max_steps) : 0;
if (steps < 1) return;
let v = PVector(line);
ctx.moveTo(v.x, v.y);
array(steps).forEach(d => {
const isInside = v.x >= 0 && v.x <= w && v.y >= 0 && v.y <= h;
if (!isInside) return;
const angle =
simplex.noise3D(v.x / noiseScale, v.y / noiseScale, seed) * TAU;
if (d >= start_step) ctx.lineTo(v.x, v.y);
else ctx.moveTo(v.x, v.y);
v.add(PVector.fromAngle(angle).setMag(stepLength));
});
});
ctx.stroke();
return ctx.canvas;
};
}