Commit ae479b63 authored by Ralf's avatar Ralf

clamp at MAX_BRIGHTNESS

parent 7c5beb0a
......@@ -29,18 +29,19 @@ B_PERIOD_SECONDS = 10.0
LED_STEP_SECONDS = 0.2
MAX_BRIGHTNESS = 40.0
MAX_BRIGHTNESS_INT = min(255, int(math.ceil(MAX_BRIGHTNESS)))
def f2i(f, minval=0.0, maxval=1.0):
'''Turn `f` into an integer color value, scaling from `[minval, maxval]`'''
# scale and round
i = int((f - minval)/(maxval - minval)*MAX_BRIGHTNESS + 0.5)
# clamp
return max(0, min(i, 255))
return max(0, min(i, MAX_BRIGHTNESS_INT))
def get_color(seconds):
r = math.sin(seconds/R_PERIOD_SECONDS*2*math.pi)
g = math.sin(seconds/G_PERIOD_SECONDS*2*math.pi)
b = math.sin(seconds/B_PERIOD_SECONDS*2*math.pi)
# to avoid things getting too bright, we set a higher upper bound
return [f2i(g, -1.0, 1.0), f2i(r, -1.0, 1.0), f2i(b, -1.0, 1.0), 0]
frame = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment