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_2.py (2191B)
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 create_slider(color): 26 slider = lv.slider(lv.scr_act()) 27 slider.set_range(0, 255) 28 slider.set_size(10, 200) 29 slider.set_style_bg_color(color, lv.PART.KNOB) 30 slider.set_style_bg_color(color.color_darken(lv.OPA._40), lv.PART.INDICATOR) 31 slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None) 32 return slider 33 34 def slider_event_cb(e): 35 # Recolor the image based on the sliders' values 36 color = lv.color_make(red_slider.get_value(), green_slider.get_value(), blue_slider.get_value()) 37 intense = intense_slider.get_value() 38 img1.set_style_img_recolor_opa(intense, 0) 39 img1.set_style_img_recolor(color, 0) 40 41 # 42 # Demonstrate runtime image re-coloring 43 # 44 # Create 4 sliders to adjust RGB color and re-color intensity 45 red_slider = create_slider(lv.palette_main(lv.PALETTE.RED)) 46 green_slider = create_slider(lv.palette_main(lv.PALETTE.GREEN)) 47 blue_slider = create_slider(lv.palette_main(lv.PALETTE.BLUE)) 48 intense_slider = create_slider(lv.palette_main(lv.PALETTE.GREY)) 49 50 red_slider.set_value(lv.OPA._20, lv.ANIM.OFF) 51 green_slider.set_value(lv.OPA._90, lv.ANIM.OFF) 52 blue_slider.set_value(lv.OPA._60, lv.ANIM.OFF) 53 intense_slider.set_value(lv.OPA._50, lv.ANIM.OFF) 54 55 red_slider.align(lv.ALIGN.LEFT_MID, 25, 0) 56 green_slider.align_to(red_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0) 57 blue_slider.align_to(green_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0) 58 intense_slider.align_to(blue_slider, lv.ALIGN.OUT_RIGHT_MID, 25, 0) 59 60 # Now create the actual image 61 img1 = lv.img(lv.scr_act()) 62 img1.set_src(img_cogwheel_argb) 63 img1.align(lv.ALIGN.RIGHT_MID, -20, 0) 64 65 lv.event_send(intense_slider, lv.EVENT.VALUE_CHANGED, None) 66 67 68 69 70