Last active
April 4, 2022 11:35
-
-
Save Dioarya/82c94ab4571b25f0e3a192468807da5a to your computer and use it in GitHub Desktop.
Color conversions
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
def hsv_to_rgb(h, s, v) -> tuple[float, float, float]: | |
# 0 <= h <= 1 | |
# 0 <= s <= 1 | |
# 0 <= v <= 1 | |
c = v * s | |
x = c * (1 - abs(h*6 % 2 - 1)) | |
m = v - c | |
rgb = ( | |
(c, x, 0), | |
(x, c, 0), | |
(0, c, x), | |
(0, x, c), | |
(x, 0, c), | |
(c, 0, x) | |
) | |
index = int(h * 6) | |
return tuple([(i + m) * 255 for i in rgb[index]]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment