Published
Edited
Jan 31, 2021
1 star
Insert cell
Insert cell
svg`<svg viewBox="0 0 100 100" style="max-width: 600px">${colors}</svg>`
Insert cell
N = 25
Insert cell
colors = {
let svg = ``;
for (let x = 0; x < N; x++) {
for (let y = 0; y < N; y++) {
let haircolor = color(x/N, y/N);
svg += `<rect x="${x/N*100}" y="${y/N*100}" width="${100/N+0.5}" height="${100/N+0.5}" fill="rgb(${haircolor.toString()})"/>`;
}
}
return svg;
}
Insert cell
function color(x, y) {
const white = [255, 255, 255];
const eumelanin = [35, 18, 11];
const pheomelanin = [218, 104, 15];

let e = lerp(white, eumelanin, x);
let p = lerp(white, pheomelanin, y);
/* this blending seems … weird? why separate per channel?? */
return [e[0] * p[0] / 255 | 0, e[1] * p[1] / 255 | 0, e[2] * p[2] / 255 | 0];
}
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