diff --git a/ledcontrol/animationcontroller.py b/ledcontrol/animationcontroller.py index e527df0..f2f9fb3 100644 --- a/ledcontrol/animationcontroller.py +++ b/ledcontrol/animationcontroller.py @@ -148,6 +148,7 @@ def getiter(obj): 'fract': utils.fract, 'blackbody_to_rgb': driver.blackbody_to_rgb, 'blackbody_correction_rgb': driver.blackbody_correction_rgb, + 'hsv_to_rgb': self.hsv_to_rgb, } restricted_locals = {} arg_names = ['t', 'dt', 'x', 'y', 'z', 'prev_state'] @@ -277,6 +278,17 @@ def calculate_palette_table(self): self.palette_length = len(palette['colors']) self.update_needed = True + def hsv_to_rgb(h, s, v): + if s == 0.0: return (v, v, v) + i = int(h*6.) # XXX assume int() truncates! + f = (h*6.)-i; p,q,t = v*(1.-s), v*(1.-s*f), v*(1.-s*(1.-f)); i%=6 + if i == 0: return (v, t, p) + if i == 1: return (q, v, p) + if i == 2: return (p, v, t) + if i == 3: return (p, q, v) + if i == 4: return (t, p, v) + if i == 5: return (v, p, q) + def get_palette_color(self, t): 'Get color from current palette corresponding to index between 0 and 1' # This gives a surprising performance improvement over doing the math in python