Public
Edited
Jan 12, 2024
7 forks
Importers
289 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
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
greys = t => `hsl(0, 0%, ${100 - t * 100}%)`
Insert cell
Insert cell
rainbow = t => `hsl(${t * 360}, 100%, 50%)`
Insert cell
Insert cell
Insert cell
d3scales = require("d3-scale-chromatic@1", "d3-interpolate@1")
Insert cell
ramp(scales.cool)
Insert cell
ramp(scales.turbo)
Insert cell
ramp(scales.inferno)
Insert cell
ramp(scales.warm)
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
procScale = (a, b, c, d) => {
const channel = (i, t) => Math.max(Math.min((a[i] + b[i] * Math.cos(Math.PI * 2 * (c[i] * t + d[i]))) * 255, 255), 0) | 0
return t => `rgb(${channel(0, t)}, ${channel(1, t)}, ${channel(2, t)})`
}
Insert cell
Insert cell
ramp(scales.procA)
Insert cell
ramp(scales.procB)
Insert cell
ramp(scales.procC)
Insert cell
ramp(scales.procD)
Insert cell
ramp(scales.procE)
Insert cell
ramp(scales.procF)
Insert cell
ramp(scales.procG)
Insert cell
ramp(scales.procH)
Insert cell
Insert cell
Insert cell
ramp(randomProc())
Insert cell
Insert cell
Insert cell
ramp(scales.geoffrey)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
imageData = readPixels('https://source.unsplash.com/featured?forest', { w: width, h: width / 2.5 , format: 'hsl', fit: true })
Insert cell
Insert cell
extractPalette = async uri => {
const palette = await Vibrant.from(uri).getPalette()
return Object.values(palette).map(d => d.rgb.reduce((acc, n) => acc + (n|0).toString(16).padStart(2, '0'), '#'))
}
Insert cell
Insert cell
Insert cell
paletteFromImage = extractPalette(uri)
Insert cell
Insert cell
Insert cell
atcq = async (url, maxColors = 12) => {
const imageData = await readPixels(url)
return ATCQ.quantizeSync(imageData.pixels, { maxColors }).map(c => rgbToHex(c.map(d => d | 0)))
}
Insert cell
paletteFromImage2 = await atcq(uri, 6)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lerpColor([255, 10, 20], [255, 135, 67], 0.5)
Insert cell
Insert cell
hexToRgb('#7abdff')
Insert cell
hexToRgb('#222')
Insert cell
Insert cell
rgbToHex([255, 10, 51])
Insert cell
Insert cell
rgbToHsl([255, 10, 51])
Insert cell
Insert cell
hslToRgb([349.9591836734694, 1, 0.5196078431372549])
Insert cell
Insert cell
rgbToHsv([255, 10, 51])
Insert cell
Insert cell
hsvToRgb([349.9591836734694, 0.9607843137254902, 1])
Insert cell
Insert cell
Insert cell
contrastYiq = ([r,g,b]) => {
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
return yiq >= 128 ? 0x0 : 0xffffff;
}
Insert cell
contrastYiq([255, 255, 255])
Insert cell
contrastYiq([200,200,200])
Insert cell
Insert cell
Insert cell
rgbToGrayscaleAverage = ([r,g,b]) => {
const gray = (r + g + b) / 3 >> 0
return [gray, gray, gray]
}
Insert cell
rgbToGrayscaleAverage([255,0,0])
Insert cell
Insert cell
rgbToGrayscaleLuma = ([r,g,b]) => {
const gray = (r * 0.299 + g * 0.587 + b * 0.114) >> 0
return [gray, gray, gray]
}
Insert cell
Insert cell
rgbToGrayscaleLuma2 = ([r,g,b]) => {
const gray = (r * 0.2126 + g * 0.7152 + b * 0.0722) >> 0
return [gray, gray, gray]
}
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

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