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_canvas_2.py (1226B)

      1 CANVAS_WIDTH   = 50
      2 CANVAS_HEIGHT  = 50
      3 LV_COLOR_CHROMA_KEY = lv.color_hex(0x00ff00)
      4 
      5 def LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h):
      6     return int(((w / 8) + 1) * h)
      7 
      8 def LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h):
      9     return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2
     10 
     11 def LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h):
     12     return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h)
     13 
     14 #
     15 # Create a transparent canvas with Chroma keying and indexed color format (palette).
     16 #
     17 
     18 # Create a button to better see the transparency
     19 btn=lv.btn(lv.scr_act())
     20 
     21 # Create a buffer for the canvas
     22 cbuf= bytearray(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT))
     23 
     24 # Create a canvas and initialize its palette
     25 canvas = lv.canvas(lv.scr_act())
     26 canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT)
     27 canvas.set_palette(0, LV_COLOR_CHROMA_KEY)
     28 canvas.set_palette(1, lv.palette_main(lv.PALETTE.RED))
     29 
     30 # Create colors with the indices of the palette
     31 c0 = lv.color_t()
     32 c1 = lv.color_t()
     33 
     34 c0.full = 0
     35 c1.full = 1
     36 
     37 # Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)
     38 canvas.fill_bg(c1, lv.OPA.COVER)
     39 
     40 # Create hole on the canvas
     41 for y in range(10,30):
     42     for x in range(5,20):
     43         canvas.set_px(x, y, c0)