From 01b33b4abac233fbf523bbd80793ad46a2927a95 Mon Sep 17 00:00:00 2001 From: Uli Raich Date: Thu, 24 Nov 2022 11:16:34 +0100 Subject: [PATCH] example(canvas): add MicroPython draw examples (#3823) --- examples/assets/font/montserrat-18.fnt | Bin 0 -> 18320 bytes .../widgets/canvas/lv_example_canvas_3.py | 31 ++++++++++++ .../widgets/canvas/lv_example_canvas_4.py | 44 ++++++++++++++++++ .../widgets/canvas/lv_example_canvas_5.py | 32 +++++++++++++ .../widgets/canvas/lv_example_canvas_6.py | 36 ++++++++++++++ .../widgets/canvas/lv_example_canvas_7.py | 33 +++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 examples/assets/font/montserrat-18.fnt create mode 100644 examples/widgets/canvas/lv_example_canvas_3.py create mode 100644 examples/widgets/canvas/lv_example_canvas_4.py create mode 100644 examples/widgets/canvas/lv_example_canvas_5.py create mode 100644 examples/widgets/canvas/lv_example_canvas_6.py create mode 100644 examples/widgets/canvas/lv_example_canvas_7.py diff --git a/examples/assets/font/montserrat-18.fnt b/examples/assets/font/montserrat-18.fnt new file mode 100644 index 0000000000000000000000000000000000000000..f483f470ee2ffcf10b2427a8599fd050530e8a8e GIT binary patch literal 18320 zcmcJ04SW^VweOmlBc)%z@0!9cJG-7}mF#e>~-dEq%+t%v!v)ERxz3Of3 zg=B`0TT$p0U+w$p!?r%PeqcYmPi~#Fc zkbq))+uH@~y=KkYYp=b&_MVx;0wVhAS8lvTL7ztxX#%-o0%Ziro~RUbB`-g}hD`-`;;u|MUH|N4Fe(=;;4C`n{tMA3bpNouf+!t{T`jIB|Gj zn5Yhl-hSuJH*SRn1^81;v#5r)&@f%6>{5QM3@dZgOVzv7b?PSd`|4q}TKl5*1MO{X zQQo)n_UBE=zb^l|{5|<^&yCBByJmc1{P`uDO1etMmtIr4sr1ECr?jn9o$&V)?w|0+ zgvk>>J8|p8cPIK2FN)qDeIlBPE}V4xq}`LoPhK$j#>o#(-ak2i%0EtdcuMb-8L_{M z-4S~x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~&fbU_Nen<*;v2T5~jK)6~jw&=Ve_xKQQ zCaDxY#smnQ)R1^LHx>K#WWdT{M$9mFMa&{Nxl00Q8F1$(Ev`&l_O;PlZ<-Gy;CoPusW5RyFL+Uk^u8?nUn^SO|U8{!j(1{g6l$x z4^O8(8XSSI2fe}L12jTv)TI$mc$rk@_#mu^u)^|sy~0rXI9^rKfbWIg;}w789raK% zduf6agr4w^`$5&=NDwIq7w#}82;i7EH0)=8=f+sJ8S~HBi8yZfhi}SVj{SZ=9^M=s4K7y4BLvU=r zTi_m7+@T?_m?Hu|A}kt#1qw+y;%gaygwn@d7tAA=qA=|BV*m{$#c*aQRlxQJ8EeWP zg0qj3m(KXZBSRxJ?2Tk#15(CkfP+4gN*#C8Aq*Js)X?zp^iYwfyqgK7GskIo&_k%D zhoOC8f&URDN5aQ@(?f#;L#SaK!K8U1m3KF=2vTIS2RBe33WGX+K9Jja}4N;J@+7;FfHABXh=Ff&H|AxaN%e82DUN5IWj9 zX}_=_1xslt1*7mL40#H06_S+*b&fsjp<<7M+~XjS0TX7V-_Y~R+>|%MLwNwMKFAEh z;Rw%EHZG~m&DVzUc#GQ4w??qX!6}0@ z5ryA}g~&^B3jUcYW%nnR#OdJ`dfuSoD}G7|DXOB540?1tlNvmZea>?c*O&qI9jAlQ z+KQp5&TLjOW>SvkQNVp^Vyq#9oh_3=Ao^*f$*3LJ4-hH|C{MDw;NXJKi0;s^it|ZI z%~K22BA-ho@(*2_cNacm_<7_Hd+>uinC6WjOJSTL=!y!%b{mA>v9k`~C-0bnk7^!D xBu50thQ=<((%5V#LmwwC3qaDyY96AnQ%$@V9@{|}^;&d~q> literal 0 HcmV?d00001 diff --git a/examples/widgets/canvas/lv_example_canvas_3.py b/examples/widgets/canvas/lv_example_canvas_3.py new file mode 100644 index 000000000..d476ecd2d --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_3.py @@ -0,0 +1,31 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 +# +# Draw a rectangle to the canvas +# +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette*/ +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) + +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_rect_dsc_t() +dsc.init() + +dsc.bg_color = lv.palette_main(lv.PALETTE.RED) +dsc.border_color = lv.palette_main(lv.PALETTE.BLUE) +dsc.border_width = 3 +dsc.outline_color = lv.palette_main(lv.PALETTE.GREEN) +dsc.outline_width = 2 +dsc.outline_pad = 2 +dsc.outline_opa = lv.OPA._50 +dsc.radius = 5 +dsc.border_width = 3 +canvas.draw_rect(10, 10, 30, 20, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_4.py b/examples/widgets/canvas/lv_example_canvas_4.py new file mode 100644 index 000000000..30439d8d2 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_4.py @@ -0,0 +1,44 @@ +import fs_driver + +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw a text to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_label_dsc_t() +dsc.init() + +dsc.color = lv.palette_main(lv.PALETTE.RED) + +try: + dsc.font = lv_font_montserrat_18 +except: + # needed for dynamic font loading + fs_drv = lv.fs_drv_t() + fs_driver.fs_register(fs_drv, 'S') + + print("Loading font montserrat_18") + font_montserrat_18 = lv.font_load("S:../../assets/font/montserrat-18.fnt") + if not font_montserrat_18: + print("Font loading failed") + else: + dsc.font = font_montserrat_18 + +dsc.decor = lv.TEXT_DECOR.UNDERLINE +print('Printing "Hello"') +canvas.draw_text(10, 10, 30, dsc, "Hello") + + diff --git a/examples/widgets/canvas/lv_example_canvas_5.py b/examples/widgets/canvas/lv_example_canvas_5.py new file mode 100644 index 000000000..2bd9ce856 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_5.py @@ -0,0 +1,32 @@ +#!/opt/bin/lv_micropython -i +# Initialize + +import lvgl as lv +import display_driver +import fs_driver + +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw an arc to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_arc_dsc_t() +dsc.init() +dsc.color = lv.palette_main(lv.PALETTE.RED) +dsc.width = 5 + +canvas.draw_arc(25, 25, 15, 0, 220, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_6.py b/examples/widgets/canvas/lv_example_canvas_6.py new file mode 100644 index 000000000..d9de0fe2c --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_6.py @@ -0,0 +1,36 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# Create an image from the png file +try: + with open('../../assets/img_star.png','rb') as f: + png_data = f.read() +except: + print("Could not find star.png") + sys.exit() + +img_star_argb = lv.img_dsc_t({ + 'data_size': len(png_data), + 'data': png_data +}) + +# +# Draw an image to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_img_dsc_t() +dsc.init() + +canvas.draw_img(5, 5, img_star_argb, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_7.py b/examples/widgets/canvas/lv_example_canvas_7.py new file mode 100644 index 000000000..ec12cc186 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_7.py @@ -0,0 +1,33 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw a line to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_line_dsc_t() +dsc.init() + +dsc.color = lv.palette_main(lv.PALETTE.RED) +dsc.width = 4 +dsc.round_end = 1 +dsc.round_start = 1 + +p = [ {"x":15,"y":15}, + {"x":35,"y":10}, + {"x":10,"y":40} ] + +canvas.draw_line(p, 3, dsc) + +