Skip to content

Instantly share code, notes, and snippets.

@slonoed
Created September 26, 2017 11:47
Show Gist options
  • Save slonoed/997aca4fd74868337137cfe42b29efed to your computer and use it in GitHub Desktop.
Save slonoed/997aca4fd74868337137cfe42b29efed to your computer and use it in GitHub Desktop.
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