Published
Edited
Sep 29, 2022
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
heads = {
randomize;
return Array.from({ length: dots }).map((_, i) => {
return {
noiseShift: CSRandom.range(1000),
phaseShift: CSRandom.value() * 2 - 1
};
});
}
Insert cell
{
ctx.globalCompositeOperation = "darken";
drawBg(redrawOpacity);
ctx.globalCompositeOperation = "source-over";
const minR = size / 6;
const maxR = size / 3;
const r = CSMath.lerp(minR, maxR, radiusRatio);
const theta = Math.PI * 2 * t;
const freq = CSMath.lerp(1 / 100, 1, freqRatio);
const maxPhaseShift = Math.PI / 8;
const initialShift = Math.PI / 2;

const drawDot = ({ noiseShift, phaseShift = 0, color }) => {
const rad = theta + phaseShift * maxPhaseShift - initialShift;
const u = Math.cos(rad);
const v = Math.sin(rad);
const dr = CSRandom.noise3D(u, v, noiseShift, freq);
const dR = (dr * (maxR - minR)) / 2;

const x = width / 2 + u * (r + dR);
const y = height / 2 + v * (r + dR);

ctx.beginPath();
ctx.fillStyle = palette.fg();
ctx.arc(x, y, 1 + 7 * dotRadiusRatio, 0, Math.PI * 2);
ctx.fill();
};

heads.forEach((dot) => drawDot(dot));
}
Insert cell
t = frame / totalFrames
Insert cell
ctx = DOM.context2d(width, height)
Insert cell
drawBg = (op = 1) => {
ctx.fillStyle = palette.bg(op);
ctx.beginPath();
ctx.fillRect(0, 0, width, height);
}
Insert cell
palette = ({
bg: (op = 1) => `hsla(0,0%,0%,${op})`,
fg: () => "hsl(0,0%,100%)"
})
Insert cell
size = Math.min(width, height)
Insert cell
Insert cell
width
Insert cell
htl.html`<style>
.progress {
--progress-fill: ${palette.bg()};
--progress-color: ${palette.fg()};
border: 1px solid var(--progress-fill);
}

.progress__bar {
display: flex;
align-items: center;
height: 1.5rem;
background-color: var(--progress-fill);
color: var(--progress-color);
}
</style>`
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