Skip to content

Instantly share code, notes, and snippets.

@vahids
Created February 3, 2020 06:39
Show Gist options
  • Select an option

  • Save vahids/47afb3967ea892583ffcb3996124c463 to your computer and use it in GitHub Desktop.

Select an option

Save vahids/47afb3967ea892583ffcb3996124c463 to your computer and use it in GitHub Desktop.
private func hsbToHSL(h: CGFloat, s: CGFloat, b: CGFloat) -> (h: CGFloat, s: CGFloat, l: CGFloat) {
// both hsv and hsl values are in [0, 1]
var newS: CGFloat = s
let l = (CGFloat(2) - s) * b / CGFloat(2)
if (l != 0) {
if (l == 1) {
newS = 0
} else if (l < 0.5) {
newS = newS * b / (l * 2)
} else {
newS = newS * b / (2 - l * 2)
}
}
return (h: h, s: newS, l: l)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment