-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds all the brand colours to the tidal interface, including a utility to adjust RGB to a color565 entry that looks a closer match perceptually. This also moves the HSV utilities out of the torch and into a utility module mimicing colorsys.
- Loading branch information
1 parent
6b46f54
commit 8836962
Showing
4 changed files
with
69 additions
and
50 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
# Ported from https://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c | ||
def hsv_to_rgb(h, s, v): | ||
i = int(h * 6) | ||
f = h * 6 - i | ||
p = v * (1 - s) | ||
q = v * (1 - f * s) | ||
t = v * (1 - (1 - f) * s) | ||
mod = i % 6 | ||
if mod == 0: | ||
r = v; g = t; b = p | ||
elif mod == 1: | ||
r = q; g = v; b = p | ||
elif mod == 2: | ||
r = p; g = v; b = t | ||
elif mod == 3: | ||
r = p; g = q; b = v | ||
elif mod == 4: | ||
r = t; g = p; b = v | ||
elif mod == 5: | ||
r = v; g = p; b = q | ||
|
||
return (int(r * 255), int(g * 255), int(b * 255)) | ||
|
||
def rgb_to_hsv(r, g, b): | ||
r = r / 255 | ||
g = g / 255 | ||
b = b / 255 | ||
max_val = max(r, g, b) | ||
min_val = min(r, g, b) | ||
v = max_val | ||
d = max_val - min_val | ||
s = 0 if max_val == 0 else d / max_val | ||
|
||
if max_val == min_val: | ||
h = 0 # achromatic | ||
else: | ||
if max_val == r: | ||
h = (g - b) / d + (6 if g < b else 0) | ||
elif max_val == g: | ||
h = (b - r) / d + 2 | ||
elif max_val == b: | ||
h = (r - g) / d + 4 | ||
h /= 6 | ||
|
||
return (h, s, v) | ||
|
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
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
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