acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_img_3.py (1343B)

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