Created
March 15, 2024 20:49
-
-
Save cmdcolin/816da3899505c1e51f6da122ad7c90f5 to your computer and use it in GitHub Desktop.
ggplot2 vs css lch colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testing | |
the JS color palette using the same thing, with "LCH" color from CSS https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch
function seq(start, end, n) {
return Array.from(
{ length: n + 1 },
(_, i) => start + (i * (end - start)) / n
);
}
function gg_color_hue(n) {
const hues = seq(15, 375, n);
return hues.map((h) => `lch(65% 100 ${h})`).slice(0, n);
}
function ColRow({ n }) {
const cols = gg_color_hue(n);
return (
<>
{cols.map((c) => (
<div
style={{
display: "inline-block",
width: 100,
height: 100,
background: c,
}}
></div>
))}
</>
);
}
export default function App() {
return <ColRow n={4} />;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the R color palette
code
alternatively this which should do the same math https://scales.r-lib.org/reference/hue_pal.html