refactor: minor refactoring and widget docs update
This commit is contained in:
55
examples/widgets/image/lv_example_image_3.py
Executable file
55
examples/widgets/image/lv_example_image_3.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user