Published
Edited
Jan 11, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
const w = width;
const h = width;
const canvas = DOM.canvas(w, h);
const context = canvas.getContext("2d");
context.fillStyle = "#2f3e46ff";
context.fillRect(0,0,w,w);
context.lineWidth = 8;
context.lineCap = 'round'
context.strokeStyle = "#7a6c5d08";
function plotCircle(circle){
context.beginPath();
context.fillStyle = colors[circle.c];
for(var rr=0; rr<circle.r; rr+=d3.randomUniform(18, 22)()){
context.arc(circle.x, circle.y, rr, 0, 2 * Math.PI);
context.fill();
}
if(circle.r>50){
for(var ii=0; ii<N; ii++){
var myD = Math.sqrt(d3.randomUniform(0, circle.r*circle.r)()); // technically more realistic
var myD = d3.randomUniform(0, circle.r)(); // looks better
var myAz = d3.randomUniform(0, 2*Math.PI)();
var newX = circle.x+myD*Math.cos(myAz);
var newY = circle.y+myD*Math.sin(myAz);
context.beginPath();
context.moveTo(circle.x, circle.y);
context.lineTo(newX, newY);
context.stroke();
plotCircle({x: newX,
y: newY,
r: d3.randomUniform(5, circle.r)(),
c: circle.c});
}
}
}

for(var c of init){
plotCircle(c)
yield canvas;
}
yield canvas;
}
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