3131__version__ = "0.0.0+auto.0"
3232__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes.git"
3333
34+ _OUTLINE_COLOR_INDEX = 1
3435
3536class Polygon (displayio .TileGrid ):
3637 # pylint: disable=too-many-arguments,invalid-name
@@ -66,9 +67,9 @@ def __init__(
6667 width = max (xs ) - min (xs ) + 1
6768 height = max (ys ) - min (ys ) + 1
6869
69- self ._palette = displayio .Palette (3 )
70+ self ._palette = displayio .Palette (2 )
7071 self ._palette .make_transparent (0 )
71- self ._bitmap = displayio .Bitmap (width , height , 3 )
72+ self ._bitmap = displayio .Bitmap (width , height , 2 )
7273
7374 if outline is not None :
7475 # print("outline")
@@ -81,7 +82,6 @@ def __init__(
8182 point_a [1 ] - y_offset ,
8283 point_b [0 ] - x_offset ,
8384 point_b [1 ] - y_offset ,
84- 1 ,
8585 )
8686
8787 super ().__init__ (
@@ -95,18 +95,17 @@ def _line(
9595 y0 : int ,
9696 x1 : int ,
9797 y1 : int ,
98- color : int ,
9998 ) -> None :
10099 if x0 == x1 :
101100 if y0 > y1 :
102101 y0 , y1 = y1 , y0
103102 for _h in range (y0 , y1 + 1 ):
104- self ._bitmap [x0 , _h ] = color
103+ self ._bitmap [x0 , _h ] = _OUTLINE_COLOR_INDEX
105104 elif y0 == y1 :
106105 if x0 > x1 :
107106 x0 , x1 = x1 , x0
108107 for _w in range (x0 , x1 + 1 ):
109- self ._bitmap [_w , y0 ] = color
108+ self ._bitmap [_w , y0 ] = _OUTLINE_COLOR_INDEX
110109 else :
111110 steep = abs (y1 - y0 ) > abs (x1 - x0 )
112111 if steep :
@@ -129,9 +128,9 @@ def _line(
129128
130129 for x in range (x0 , x1 + 1 ):
131130 if steep :
132- self ._bitmap [y0 , x ] = color
131+ self ._bitmap [y0 , x ] = _OUTLINE_COLOR_INDEX
133132 else :
134- self ._bitmap [x , y0 ] = color
133+ self ._bitmap [x , y0 ] = _OUTLINE_COLOR_INDEX
135134 err -= dy
136135 if err < 0 :
137136 y0 += ystep
@@ -143,13 +142,13 @@ def _line(
143142 def outline (self ) -> Optional [int ]:
144143 """The outline of the polygon. Can be a hex value for a color or
145144 ``None`` for no outline."""
146- return self ._palette [1 ]
145+ return self ._palette [_OUTLINE_COLOR_INDEX ]
147146
148147 @outline .setter
149148 def outline (self , color : Optional [int ]) -> None :
150149 if color is None :
151- self ._palette [1 ] = 0
152- self ._palette .make_transparent (1 )
150+ self ._palette [_OUTLINE_COLOR_INDEX ] = 0
151+ self ._palette .make_transparent (_OUTLINE_COLOR_INDEX )
153152 else :
154- self ._palette [1 ] = color
155- self ._palette .make_opaque (1 )
153+ self ._palette [_OUTLINE_COLOR_INDEX ] = color
154+ self ._palette .make_opaque (_OUTLINE_COLOR_INDEX )
0 commit comments