Published
Edited
Apr 25, 2020
Fork of SVG template
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
step = 10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
attractors = array(nbAttractors).map(d => PVector(margin + Math.random() * (w - 2 * margin) | 0, margin + Math.random() * (h - 2 * margin) | 0))
Insert cell
Insert cell
svg`<svg width="${w}" height="${h}">
<rect x="0" y="0" width="${w}" height="${h}" stroke="none " fill="${colorScale(1)}"></rect>

<g>
${(() => {
return attractors.map(d => `<circle stroke="none" fill="none" cx="${d.x}" cy="${d.y}" r="5" />`).join('\n')
})()}
</g>
<g transform="translate(${marginX}, ${marginY})">
${(() => {
return array(ny).map(i => {
const y = i * step
return array(nx).map(j => {
const x = j * step
const v = PVector(x, y)
// find closest attractor
const closest = attractors[attractors.map((d, i) => ({index: i, dist: v.clone().sub(d).mag()}))
.sort((a, b) => a.dist < b.dist ? -1 : a.dist > b.dist ? 1 : 0)[0].index]
const r = v.clone().sub(closest).mag()
let f = .3
return `<path transform="translate(${x}, ${y}) rotate(45) scale(${r/5})" opacity="0.5" fill="${colorScale(1 - r/400)}" stroke="none" d="M 1 0 C ${f} 0, 0 ${f}, 0 1 C 0 ${f}, -${f} 0, -1 0 C -${f} 0, 0 -${f}, 0 -1 C 0 -${f}, ${f} 0, 1 0" />`
}).join('\n')
}).join('\n')
})()}
</g>
</svg>`
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