Published
Edited
Oct 17, 2021
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
canvas = {
const length = points.length * 2;
const frequence = f * 1e-3;
const maxCount = mc;

let roots = new Float64Array(length);
let vectors = Float64Array.from({ length }, () => 0);
let now = performance.now();
let cells = [];

roots = points.flat();

context.fillStyle = `rgb(${colors.bg})`;
context.fillRect(0, 0, width, height);

while (!paused) {
const z = now * v * 1e-5;
const newPoints = Math.floor(Math.random() * c);

// Set the fill style and draw a rectangle

let i = -1;

if (cells.length > maxCount) {
const died = cells.splice(newPoints);
console.log(died);
}

cells = [...cells, ...pickStartingPoints(newPoints)];

/*for (let [x, y] of points) {
const n = noise(x * frequence, y * frequence, z);
const t = (n % TAU) * Math.PI;

vectors[i++] = l * Math.cos(t);
vectors[i++] = l * Math.sin(t);
}*/

//context.globalCompositeOperation = "darken";
//context.globalCompositeOperation = "lighten";
context.fillStyle = `rgba(${colors.bg}, 0.1`;
context.fillRect(0, 0, width, height);
context.globalCompositeOperation = "source-over";

//console.log(cells);

// Use the set of points that is grouped by y-axis coordinates
cells = cells.filter(([x,y])=>x>-width&&x<2*width&&y>-height&&y<2*height).map(([x, y, color], j) => {
const n = noise(x * frequence, y * frequence + Math.sin(z), z);
const t = (n % TAU) * Math.PI;
const dx = l * Math.cos(t);
const dy = l * Math.sin(t);

//drawPoint(x, y, colors.dark, 2);
//drawPoint(x + dx, y + dy);

if (x > 0 && x < width && y > 0 && y < height) {
drawVector(x, y, dx, dy, color, r);
}

x = x + dx * v;
y = y + dy * v;

return [x, y, color];
});

mutable fps =
(1 + mutable fps) * (1 + .984e-3 * (now - (now = performance.now())));

yield context.canvas;
}
yield context.canvas;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
drawVector = (x, y, dx, dy, color = colors.solid, stroke = 0.3) => {
context.beginPath();
context.lineWidth = stroke;
context.strokeStyle = color;
//context.strokeStyle = pickColor(Math.random());
d3
.line()
.x(p => p[0])
.y(p => p[1])
.curve(d3.curveBasis)
.context(context)([[x, y], [x + dx, y + dy]]);
context.stroke();
context.closePath();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
width=2048
Insert cell
Insert cell
Insert cell
pickColor = //d3.interpolateWarm //interpolateYlGnBu //interpolateSpectral //interpolateGreys
d3.interpolateCubehelixDefault //interpolateRdPu
/*
.scaleLinear()
.domain([0, 1])
.range(["#EC609F", "#FCF4FB"])
*/
Insert cell
pickStartingPoints = (length = 1) => {
return Array.from({ length }, () => {
return [
...points[Math.floor(Math.random() * points.length)],
pickColor(Math.cos(Math.PI * Date.now() * 0.01))
];
});
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more