Skip to content

Commit 2f70924

Browse files
authored
Add option to draw polylines (not closed polygons)
1 parent 63f9d2f commit 2f70924

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

adafruit_display_shapes/polygon.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Various common shapes for use with displayio - Polygon shape!
1010
1111
12-
* Author(s): Melissa LeBlanc-Williams
12+
* Author(s): Melissa LeBlanc-Williams, Maciej Sokołowski
1313
1414
Implementation Notes
1515
--------------------
@@ -39,14 +39,19 @@ class Polygon(displayio.TileGrid):
3939
:param list points: A list of (x, y) tuples of the points
4040
:param int|None outline: The outline of the polygon. Can be a hex value for a color or
4141
``None`` for no outline.
42+
:param bool close: Wether to connect first and last point.
4243
"""
4344

4445
def __init__(
4546
self,
4647
points: List[Tuple[int, int]],
4748
*,
4849
outline: Optional[int] = None,
50+
close: bool = True,
4951
) -> None:
52+
if close:
53+
points.append(points[0])
54+
5055
xs = []
5156
ys = []
5257

@@ -68,12 +73,9 @@ def __init__(
6873
if outline is not None:
6974
# print("outline")
7075
self.outline = outline
71-
for index, _ in enumerate(points):
76+
for index, _ in enumerate(points[:-1]):
7277
point_a = points[index]
73-
if index == len(points) - 1:
74-
point_b = points[0]
75-
else:
76-
point_b = points[index + 1]
78+
point_b = points[index + 1]
7779
self._line(
7880
point_a[0] - x_offset,
7981
point_a[1] - y_offset,

0 commit comments

Comments
 (0)