File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99Various 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
1414Implementation 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 ,
You can’t perform that action at this time.
0 commit comments