Commit 6c52c4fd authored by Ralf's avatar Ralf

some basic animation

parent 98c07b0d
import badge
import ugfx
import time
import math
badge.init()
ugfx.init()
......@@ -10,9 +11,10 @@ ugfx.clear(ugfx.BLACK)
ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5)
ugfx.box(30, 30, 50, 50, ugfx.WHITE)
NAME = "Hacksaar"
ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(130, 50, "Hacksaar", "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width("Hacksaar", "PermanentMarker22")
ugfx.string(130, 50, NAME, "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width(NAME, "PermanentMarker22")
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)
......@@ -20,11 +22,33 @@ ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.flush()
# LED fanciness
def all_same_color(r, g, b, w):
led_array = [g, r, b, w]
badge.leds_send_data(bytes(led_array*6), 24)
FRAMERATE = 1/30.0
R_PERIOD_SECONDS = 3.0
G_PERIOD_SECONDS = 3.1
B_PERIOD_SECONDS = 10.0
LED_STEP_SECONDS = 0.2
MAX_BRIGHTNESS = 40.0
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))
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
while True:
for r in range(0, 256):
all_same_color(r, 255-r, 0, 2)
time.sleep(0.02)
seconds = frame*FRAMERATE
leds = []
for led in range(0, 6):
leds += get_color(seconds + led*LED_STEP_SECONDS)
badge.leds_send_data(bytes(leds), 24)
frame += 1
time.sleep(FRAMERATE)
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