Published
Edited
Apr 25, 2020
3 forks
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
n = 50
Insert cell
gridSize = 30
Insert cell
brushLength = 10
Insert cell
p = getRandomPalette()
Insert cell
palette = shuffle(p)
Insert cell
Insert cell
{
const SVG = svg`<svg width="${w}" height="${h}"></svg>`

const rc = rough.svg(SVG)
const addToSVG = el => SVG.appendChild(el)

addToSVG(rc.rectangle(0, 0, w, h, {
fill: palette[0],
fillWeight: 4,
fillStyle: 'sunburst',
hachureAngle: randInt(720),
stroke: 'none'
}))

array(n).forEach(i => {
addToSVG(rc.path(`${polygonPath(randInt(w), randInt(h), randInt(12), randInt(50, (n-i) * 10), random(TAU))}`, {
fill: palette[randInt(1,palette.length)],
fillWeight: randInt(1, 5),
// ['hachure', 'solid', 'zigzag', 'cross-hatch', 'dots', 'sunburst', 'dashed', 'zigzag-line']
fillStyle: 'sunburst',
hachureAngle: randInt(720),
stroke: 'none'
}))
})
return SVG
}
Insert cell
polygonPath = (cx, cy, n, rad, startAngle = 0) => {
return array(n).map(i => {
const angle = startAngle + TAU/n * i
const x = cx + Math.cos(angle) * rad
const y = cy + Math.sin(angle) * rad
return `${i === 0 ? 'M' : 'L'} ${x} ${y}`
}).join(' ')
}
Insert cell
coin = () => random() < .5 ? -1 : 1
Insert cell
Insert cell
Insert cell
rough = require('roughjs@4.0.4').catch(() => window["rough"])
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