Skip to content

Commit db96778

Browse files
committed
fix for platforms without bitmaptools
1 parent 95f0ab0 commit db96778

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

adafruit_display_shapes/polygon.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
except ImportError:
2727
pass
2828

29-
import bitmaptools
29+
try:
30+
import bitmaptools
31+
32+
HAVE_BITMAPTOOLS = True
33+
except ImportError:
34+
HAVE_BITMAPTOOLS = False
35+
3036
import displayio
3137

3238
__version__ = "0.0.0+auto.0"
@@ -144,14 +150,19 @@ def pt_on(x, y, pt_size=1):
144150
if pt_size > 1:
145151
x = x + pt_size // 2
146152
y = y + pt_size // 2
147-
bitmaptools.fill_region(
148-
bitmap,
149-
x - (pt_size // 2),
150-
y - (pt_size // 2),
151-
x + (pt_size // 2),
152-
y + (pt_size // 2),
153-
color,
154-
)
153+
if HAVE_BITMAPTOOLS:
154+
bitmaptools.fill_region(
155+
bitmap,
156+
x - (pt_size // 2),
157+
y - (pt_size // 2),
158+
x + (pt_size // 2),
159+
y + (pt_size // 2),
160+
color,
161+
)
162+
else:
163+
for p_x in range(x - (pt_size // 2), x + (pt_size // 2)):
164+
for p_y in range(y - (pt_size // 2), y + (pt_size // 2)):
165+
Polygon._safe_draw(bitmap, (p_x, p_y), color)
155166
else:
156167
Polygon._safe_draw(bitmap, (x, y), color)
157168

0 commit comments

Comments
 (0)