add experimental animation with `async for`

This commit is contained in:
Jan Pochyla 2016-08-08 14:53:42 +02:00 committed by Pavol Rusnak
parent 3eaf001eef
commit 312859ba71
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 27 additions and 3 deletions

View File

@ -10,9 +10,14 @@ async def swipe_to_rotate():
async def animate_logo():
def func(foreground):
ui.display.icon(0, 0, res.load('apps/homescreen/res/trezor.toig'), foreground, ui.BLACK)
await ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
# def func(foreground):
# ui.display.icon(0, 0, res.load(
# 'apps/homescreen/res/trezor.toig'), foreground, ui.BLACK)
# await ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
async for fg in ui.pulse_animation(ui.WHITE, ui.GREY, speed=400000):
icon = res.load('apps/homescreen/res/trezor.toig')
ui.display.icon(0, 0, icon, fg, ui.BLACK)
@unimport_gen

View File

@ -76,6 +76,25 @@ def animate_pulse(func, ca, cb, speed=200000, delay=30000):
yield loop.Sleep(delay)
class pulse_animation:
def __init__(self, color_a, color_b, speed=200000, delay=30000):
self.color_a = color_a
self.color_b = color_b
self.speed = speed
self.delay = delay
async def __aiter__(self):
return self
async def __anext__(self):
# normalize sin from interval -1:1 to 0:1
y = 0.5 + 0.5 * math.sin(utime.ticks_us() / self.speed)
c = blend(self.color_a, self.color_b, y)
await loop.Sleep(self.delay)
return c
def rotate_coords(pos: tuple) -> tuple:
r = display.orientation()
if r == 0: