Published
Edited
May 27, 2018
1 star
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);

const particles = new Set();
for (let i = 0; i < count; ++i) {
particles.add({
x: width / 2,
y: height / 2,
a: i / count * 2 * Math.PI
});
}
// context.lineWidth = 0.5;
while (particles.size) {
for (const p of particles) {
const a = p.a * 2;
p.x += Math.cos(a) //+ simplex.noise2D(p.x, p.y);
p.y += Math.sin(a) //+ simplex.noise2D(p.x, p.y);
context.fillRect(p.x, p.y, 1, 1);
if (p.x < 0 || p.x >= width || p.y < 0 || p.y >= height) {
particles.delete(p);
}
}
yield context.canvas;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more