Skip to content

Instantly share code, notes, and snippets.

@svgeesus
Last active May 3, 2021 18:00
Show Gist options
  • Save svgeesus/6e9bc5c573fc5afcb11e9ab47c6e1e2f to your computer and use it in GitHub Desktop.
Save svgeesus/6e9bc5c573fc5afcb11e9ab47c6e1e2f to your computer and use it in GitHub Desktop.

CSS Color 5 simple mix

Effect of mixing colorspace

50% white, 50% black, in LCH, XYZ

For https://drafts.csswg.org/css-color-5/#color-mix

let color = new Color("white");
color.to("lch").toString({precision:6});
color.to("xyz").toString({precision:6});
let color2 = new Color("black");
color2.to("lch").toString({precision:6});
color2.to("xyz").toString({precision:6});
let mix_lch= color.range(color2, {
    space: "lch", // interpolation space
    outputSpace: "srgb"
});
let mix_xyz= color.range(color2, {
    space: "xyz", // interpolation space
    outputSpace: "srgb"
});
let mix_srgb= color.range(color2, {
    space: "srgb", // interpolation space
    outputSpace: "srgb"
});
let blend_lch = mix_lch(.5);
blend_lch.to("lch").toString({precision:6});
let blend_xyz = mix_xyz(.5);
blend_xyz.to("lch").toString({precision:6});
let blend_srgb = mix_srgb(.5);
blend_srgb.to("lch").toString({precision:6});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment