Skip to content

Commit c351c76

Browse files
committed
Add example file for plotting lines
Thanks to s-light for originally contributing this!
1 parent baf6cb4 commit c351c76

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: 2021 Stefan Krüger
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#############################
5+
"""
6+
This is a basic demonstration of a Cartesian widget for line-ploting
7+
"""
8+
9+
import time
10+
import board
11+
import displayio
12+
from adafruit_displayio_layout.widgets.cartesian import Cartesian
13+
14+
# create the display on the PyPortal or Clue or PyBadge(for example)
15+
display = board.DISPLAY
16+
# otherwise change this to setup the display
17+
# for display chip driver and pinout you have (e.g. ILI9341)
18+
19+
# pybadge display: 160x128
20+
# Create a Cartesian widget
21+
# https://circuitpython.readthedocs.io/projects/displayio-layout/en/latest/api.html#module-adafruit_displayio_layout.widgets.cartesian
22+
my_plane = Cartesian(
23+
x=15, # x position for the plane
24+
y=2, # y plane position
25+
width=140, # display width
26+
height=105, # display height
27+
xrange=(0, 10), # x range
28+
yrange=(0, 10), # y range
29+
)
30+
31+
my_group = displayio.Group()
32+
my_group.append(my_plane)
33+
display.show(my_group) # add high level Group to the display
34+
35+
data = [
36+
# (0, 0), # we do this point manually - so we have no wait...
37+
(1, 1),
38+
(2, 1),
39+
(2, 2),
40+
(3, 3),
41+
(4, 3),
42+
(4, 4),
43+
(5, 5),
44+
(6, 5),
45+
(6, 6),
46+
(7, 7),
47+
(8, 7),
48+
(8, 8),
49+
(9, 9),
50+
(10, 9),
51+
(10, 10),
52+
]
53+
54+
print("examples/displayio_layout_cartesian_lineplot.py")
55+
56+
# first point without a wait.
57+
my_plane.add_plot_line(0, 0)
58+
for x, y in data:
59+
my_plane.add_plot_line(x, y)
60+
time.sleep(0.5)
61+
62+
while True:
63+
pass

0 commit comments

Comments
 (0)