Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make nice colors
// Return "infinite" sequence of HSL colors
function* colorMaker({distance = 1, saturation, luminosity, shift = 0}) {
let colorIndex = 0
while (true) {
const hue = (colorIndex * distance + shift) % 359
yield `hsl(${hue}, ${saturation}%, ${luminosity}%)`
colorIndex++
}
}
// usage
const color = colorMaker({distance: 40, saturation: 65, luminosity: 68})
color().next().value // -> color value for component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment