Created
August 21, 2021 18:19
-
-
Save YonatanKra/840b620107a25c3008297ef2c64f1bf5 to your computer and use it in GitHub Desktop.
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
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