annotate ub-timer/colorsys_local.py @ 24:872d8155ed0c default tip

start ub-timer
author drewp@bigasterisk.com
date Tue, 24 Dec 2024 21:36:53 -0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
1
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
2 def hsv_to_rgb(h, s, v):
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
3 h = max(0, min(h, 1))
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
4 s = max(0, min(s, 1))
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
5 v = max(0, min(v, 1))
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
6 if s == 0:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
7 return (v, v, v)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
8 i = int(h * 6)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
9 f = h * 6 - i
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
10 p, q, t = v * (1 - s), v * (1 - s * f), v * (1 - s * (1 - f))
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
11 i = i % 6
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
12 if i == 0:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
13 return (v, t, p)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
14 if i == 1:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
15 return (q, v, p)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
16 if i == 2:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
17 return (p, v, t)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
18 if i == 3:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
19 return (p, q, v)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
20 if i == 4:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
21 return (t, p, v)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
22 if i == 5:
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
23 return (v, p, q)
872d8155ed0c start ub-timer
drewp@bigasterisk.com
parents:
diff changeset
24 raise