Created
February 3, 2020 06:39
-
-
Save vahids/47afb3967ea892583ffcb3996124c463 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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