Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created August 21, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/840b620107a25c3008297ef2c64f1bf5 to your computer and use it in GitHub Desktop.
Save YonatanKra/840b620107a25c3008297ef2c64f1bf5 to your computer and use it in GitHub Desktop.
function landscapeColors(percentage) {
const colorVariety = 3;
const colorStep = 360 / colorVariety;
const colorIndex = Math.floor(percentage * colorVariety);
const hue =
colorStep * colorIndex + colorStep * (percentage - (colorIndex * 100) / 3);
const lightness = percentage < 0.01 ? 100 : 50;
const saturation = 100;
return `hsl(${hue < 360 ? hue : hue - 360}, ${saturation}%, ${lightness}%)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment