Published
Edited
Apr 25, 2020
1 fork
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
palette = getRandomPalette().map(hex => ({hex, lightness: rgbToHsl(hexToRgb(hex))[2]}))
.sort((a,b) => a.lightness > b.lightness ? 1 : -1)
.map(d => d.hex)
Insert cell
Insert cell
{
const SVG = svg`<svg width="${w}" height="${h}">
<rect x="0" y="0" width="${w}" height="${h}" stroke="none" fill="white" />
</svg>`
const rc = rough.svg(SVG)
const addToSVG = el => SVG.appendChild(el)

addToSVG(rc.rectangle(0, 0, w, h, {
fill: palette[0],
fillWeight: 3.5,
fillStyle: 'sunburst',
hachureAngle: randInt(720),
stroke: 'none'
}))
thresholds.forEach((d, i) => {
addToSVG(rc.path(path(contour(contourData, i/palette.length)), {
roughness: 2.8,
fill: palette[i],
fillWeight: 2,
// ['hachure', 'solid', 'zigzag', 'cross-hatch', 'dots', 'sunburst', 'dashed', 'zigzag-line']
fillStyle: 'sunburst',
hachureAngle: randInt(720),
stroke: palette[i]
}))
})
return SVG
}
Insert cell
Insert cell
imageData = readPixels('https://source.unsplash.com/featured?streetlife', { w, h , format: 'hsl', fit: true })
Insert cell
contourData = imageData.pixels.map(p => p[2]) // use lightness for contours
Insert cell
Insert cell
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