Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add hsv to rgb conversion function in restricted list #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ledcontrol/animationcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down