1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/examples/widgets/img/lv_example_img_3.py
2023-10-24 09:41:51 +02:00

56 lines
1.2 KiB
Python
Executable File

#!/opt/bin/lv_micropython -i
import usys as sys
import lvgl as lv
import display_driver
# Create an image from the png file
try:
with open('../../assets/image_cogwheel_argb.png','rb') as f:
png_data = f.read()
except:
print("Could not find image_cogwheel_argb.png")
sys.exit()
image_cogwheel_argb = lv.image_dsc_t({
'data_size': len(png_data),
'data': png_data
})
def set_angle(image, v):
image.set_angle(v)
def set_zoom(image, v):
image.set_zoom(v)
#
# Show transformations (zoom and rotation) using a pivot point.
#
# Now create the actual image
image = lv.image(lv.screen_active())
image.set_src(image_cogwheel_argb)
image.align(lv.ALIGN.CENTER, 50, 50)
image.set_pivot(0, 0) # Rotate around the top left corner
a1 = lv.anim_t()
a1.init()
a1.set_var(image)
a1.set_custom_exec_cb(lambda a,val: set_angle(image,val))
a1.set_values(0, 3600)
a1.set_time(5000)
a1.set_repeat_count(lv.ANIM_REPEAT_INFINITE)
lv.anim_t.start(a1)
a2 = lv.anim_t()
a2.init()
a2.set_var(image)
a2.set_custom_exec_cb(lambda a,val: set_zoom(image,val))
a2.set_values(128, 256)
a2.set_time(5000)
a2.set_playback_time(3000)
a2.set_repeat_count(lv.ANIM_REPEAT_INFINITE)
lv.anim_t.start(a2)