Skip to content

Instantly share code, notes, and snippets.

@Dioarya
Last active April 4, 2022 11:35
Show Gist options
  • Save Dioarya/82c94ab4571b25f0e3a192468807da5a to your computer and use it in GitHub Desktop.
Save Dioarya/82c94ab4571b25f0e3a192468807da5a to your computer and use it in GitHub Desktop.
Color conversions
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