render = {
const particleContext = DOM.context2d(w, h);
const randomWalkParticles = Array.from({length: activeParticles},
() => [Math.random() * w,
Math.random() * h,
(Math.random() - 0.5),
(Math.random() - 0.5)]);
const minDistance2 = minDistance * minDistance;
const maxDistance2 = maxDistance * maxDistance;
for(let iterations = 0; iterations < maxIterations; iterations++){
particleContext.strokeStyle= colorScale(iterations);
for (let i = 0; i < activeParticles; ++i) {
for (let j = i + 1; j < activeParticles; ++j) {
const pi = randomWalkParticles[i];
const pj = randomWalkParticles[j];
const dx = pi[0] - pj[0];
const dy = pi[1] - pj[1];
const d2 = dx * dx + dy * dy;
if (d2 < maxDistance2) {
particleContext.globalAlpha = d2 > minDistance2 ? (maxDistance2 - d2) / (maxDistance2 - minDistance2) : 1;
particleContext.beginPath();
particleContext.moveTo(pi[0], pi[1]);
particleContext.lineTo(pj[0], pj[1]);
particleContext.stroke();
}
}
}
let c = particleContext.canvas;
c.style.width= "100%";
c.style.height= "100%";
c.style.position= "absolute";
c.style.zIndex= -1;
c.style.top= 0;
c.style.left= 0;
yield c;
for (const p of randomWalkParticles) {
p[0] += p[2];
p[1] += p[3];
if (p[0] < (0 - maxDistance)) p[0] = w + maxDistance;
else if (p[0] > (width + maxDistance)) p[0] = 0 - maxDistance;
if (p[1] < (0 - maxDistance)) p[1] = h + maxDistance;
else if (p[1] > (h + maxDistance)) p[1] = 0 - maxDistance;
p[2] += 0.3 * (Math.random() - 0.5) - .01 * p[2];
p[3] += 0.3 * (Math.random() - 0.5) - .01 * p[3];
}
}
}