add ui.blend

pull/25/head
Jan Pochyla 9 years ago committed by Pavol Rusnak
parent 904127f263
commit de83114dc7
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -91,7 +91,7 @@ def tap_to_confirm(address, amount, currency):
f.seek(0)
ui.display.icon(3, 170, f.read(), _background, foreground)
yield from ui.animate_pulse(func) # , DELAY=10000)
yield from ui.animate_pulse(func, ui.BLACK, ui.GREY) # , delay=10000)
'''
def on_read():
@ -130,8 +130,7 @@ def homescreen():
def func(foreground):
f.seek(0)
ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
yield from ui.animate_pulse(func, SPEED=400000, BASE_COLOR=(0xff, 0xff, 0xff), MIN_COLOR=0xaa, MAX_COLOR=0xff)
yield from ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
def run():
ui.touch.start(lambda x, y: print('touch start %d %d\n' % (x, y)))

@ -38,14 +38,20 @@ NORMAL = const(1)
BOLD = const(2)
def animate_pulse(func, SPEED=200000, DELAY=30000, BASE_COLOR=(0x00, 0x00, 0x00), MIN_COLOR=0x00, MAX_COLOR=0x80):
while True:
y = 1 + math.sin(utime.ticks_us() / SPEED)
def lerpi(a: int, b: int, t: float) -> int:
return int(a + t * (b - a))
# Normalize color from interval 0:2 to MIN_COLOR:MAX_COLOR
col = int((MAX_COLOR - MIN_COLOR) / 2 * y) + MIN_COLOR
foreground = rgbcolor(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col)
def blend(ca: int, cb: int, t: float) -> int:
return rgbcolor(lerpi((ca >> 8) & 0xF8, (cb >> 8) & 0xF8, t),
lerpi((ca >> 3) & 0xFC, (cb >> 3) & 0xFC, t),
lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t))
func(foreground)
yield loop.Sleep(DELAY)
def animate_pulse(func, ca, cb, speed=200000, delay=30000):
while True:
# normalize sin from interval -1:1 to 0:1
y = 0.5 + 0.5 * math.sin(utime.ticks_us() / speed)
c = blend(ca, cb, y)
func(c)
yield loop.Sleep(delay)

Loading…
Cancel
Save