Skip to content

Commit b0cd941

Browse files
Draw circles
1 parent 5556540 commit b0cd941

File tree

1 file changed

+34
-6
lines changed
  • internal_filesystem/apps/com.example.draw/assets

1 file changed

+34
-6
lines changed

internal_filesystem/apps/com.example.draw/assets/draw.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import lvgl as lv
44

5+
DARKPINK = lv.color_hex(0xEC048C)
6+
57
def touch_cb(event):
68
global canvas
79
event_code=event.get_code()
@@ -15,12 +17,38 @@ def touch_cb(event):
1517
point = lv.point_t()
1618
indev.get_point(point)
1719
x, y = point.x, point.y
18-
#import random
19-
#x = random.randrange(1,200)
20-
#y = random.randrange(1,200)
21-
#print(f"got indev {x} {y} {point}")
22-
#canvas.draw_arc(x, y, 5, 0, 360, lv.color_black())
23-
canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER)
20+
#
21+
# drawing a point works:
22+
#canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER)
23+
#
24+
# drawing a square like this works:
25+
#for dx in range(-5,5):
26+
# for dy in range(-5,5):
27+
# canvas.set_px(x+dx,y+dy,DARKPINK,lv.OPA.COVER)
28+
#
29+
# drawing a circle works:
30+
radius = 7 # Set desired radius
31+
for dx in range(-radius, radius):
32+
for dy in range(-radius, radius):
33+
if dx * dx + dy * dy <= radius * radius:
34+
canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER)
35+
# Line drawing like this doesn't work:
36+
layer = lv.layer_t()
37+
canvas.init_layer(layer)
38+
dsc = lv.draw_line_dsc_t()
39+
dsc.color = DARKPINK
40+
dsc.width = 4
41+
dsc.round_end = 1
42+
dsc.round_start = 1
43+
dsc.p1 = lv.point_precise_t()
44+
dsc.p1.x = x
45+
dsc.p1.y = y
46+
dsc.p2 = lv.point_precise_t()
47+
dsc.p2.x = 100
48+
dsc.p2.y = 200
49+
#layer.draw_line(dsc) doesnt exist!
50+
lv.draw_line(layer,dsc) # doesnt do anything!
51+
canvas.finish_layer(layer)
2452
else:
2553
print("no indev!")
2654

0 commit comments

Comments
 (0)