1#!/opt/bin/lv_micropython -i
2import usys as sys
3import lvgl as lv
4import display_driver
5from imagetools import get_png_info, open_png
6
7# Register PNG image decoder
8decoder = lv.img.decoder_create()
9decoder.info_cb = get_png_info
10decoder.open_cb = open_png
11
12# Create an image from the png file
13try:
14    with open('../../assets/img_cogwheel_argb.png','rb') as f:
15        png_data = f.read()
16except:
17    print("Could not find img_cogwheel_argb.png")
18    sys.exit()
19
20img_cogwheel_argb = lv.img_dsc_t({
21  'data_size': len(png_data),
22  'data': png_data
23})
24
25def set_angle(img, v):
26    img.set_angle(v)
27
28def set_zoom(img, v):
29    img.set_zoom(v)
30
31
32#
33# Show transformations (zoom and rotation) using a pivot point.
34#
35
36# Now create the actual image
37img = lv.img(lv.scr_act())
38img.set_src(img_cogwheel_argb)
39img.align(lv.ALIGN.CENTER, 50, 50)
40img.set_pivot(0, 0)               # Rotate around the top left corner
41
42a1 = lv.anim_t()
43a1.init()
44a1.set_var(img)
45a1.set_custom_exec_cb(lambda a,val: set_angle(img,val))
46a1.set_values(0, 3600)
47a1.set_time(5000)
48a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
49lv.anim_t.start(a1)
50
51a2 = lv.anim_t()
52a2.init()
53a2.set_var(img)
54a2.set_custom_exec_cb(lambda a,val: set_zoom(img,val))
55a2.set_values(128, 256)
56a2.set_time(5000)
57a2.set_playback_time(3000)
58a2.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
59lv.anim_t.start(a2)
60
61
62