Public
Edited
Nov 20, 2022
Importers
7 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
grey = ([r,g,b]) => gamma((degamma(r) + degamma(g) + degamma(b))/3)
Insert cell
md`Let's try that approach and compute a grey value averaging the three component across the gradient, the first in gamma space and the second in linear space.`
Insert cell
Insert cell
Insert cell
Insert cell
luma = ([r,g,b]) => 0.2126*r + 0.7152*g + 0.0722*b
Insert cell
Insert cell
luminance = ([r,g,b]) => 0.2126*degamma(r) + 0.7152*degamma(g) + 0.0722*degamma(b)
Insert cell
Insert cell
lightness = (rgb)=>{
// This is from: https://stackoverflow.com/a/56678483/4100249
const y = luminance(rgb)
return (y <= (216/24389) ? y * (24389/27) : Math.pow(y,(1/3)) * 116 - 16) / 100.0
}
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
huedistance = (a,b) => {
const d = Math.abs(hue(a) - hue(b))
return 2 * (d > 0.5 ? 1 - d : d)
}
Insert cell
Insert cell
hsl(hex(HSLColor))
Insert cell
viewof HSLColor = color()
Insert cell
saturation = rgb => hsl(rgb)[2]
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
degammasRGB = _ => _ <= 0.04045 ? _/12.92 : Math.pow( ( _ + 0.055) / 1.055, 2.4)
Insert cell
gammasRGB = _ => _ <= 0.0031308 ? _ * 12.92 : 1.055 * Math.pow(_, 1.0/2.4) - 0.055
Insert cell
md`Note that according to the [WCAG](https://www.w3.org/TR/WCAG21/#dfn-relative-luminance), the gamma expansion threshold is different in sRGB, from 0.04045 (what we have in *degammasRGB*) to 0.03928, however that difference should have a negligible impact.`
Insert cell
Insert cell
Insert cell
Insert cell
stylesheet(Stylesheet)
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