Published
Edited
Apr 25, 2020
4 forks
27 stars
Insert cell
Insert cell
Insert cell
Insert cell
seed = Date.now()
Insert cell
noiseScale = 1200
Insert cell
margin = 50
Insert cell
length = 35
Insert cell
strokeWidth = 8
Insert cell
strokeCap = 'square' // butt, square or round
Insert cell
nMax = 15000
Insert cell
p = getRandomPalette()
Insert cell
palette = shuffle(p)
Insert cell
Insert cell
svg`<svg width="${w}" height="${h}">
<rect x="0" y="0" width="${w}" height="${h}" stroke="none" fill="${palette[0]}"></rect>

<g>
${(() => {
const lines = []

return array(nMax).map(d => {
const pos = PVector(Math.random(), Math.random()).mult(PVector(w, h).sub(2 * margin)).add(margin)
const angle = simplex.noise3D(pos.x / noiseScale, pos.y / noiseScale, seed) * Math.PI
const v = PVector.fromAngle(angle).setMag(length/2)
const line = new Line(pos.clone().add(v), pos.clone().sub(v))

if(lines.length < 1 || getIntersections(line, lines).length < 1) {
lines.push(line)
return `<polyline
stroke-width="${strokeWidth}"
stroke-linecap="${strokeCap}"
stroke="${palette[1 + Math.random() * (palette.length - 1) | 0]}"
points="${line.a.x},${line.a.y} ${line.b.x},${line.b.y}"
/>`
}
}).filter(d => d).join('\n')
})()}
</g>
</svg>`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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