Skip to content

Commit c22eca9

Browse files
authored
Merge pull request #24 from boo13/draw-circle
Add ability to draw circle
2 parents f9264dd + cede4f4 commit c22eca9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

adafruit_framebuf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,32 @@ def vline(self, x, y, height, color):
215215
"""Draw a vertical line up to a given length."""
216216
self.rect(x, y, 1, height, color, fill=True)
217217

218+
def circle(self, center_x, center_y, radius, color):
219+
"""Draw a circle at the given midpoint location, radius and color.
220+
The ```circle``` method draws only a 1 pixel outline."""
221+
x = radius - 1
222+
y = 0
223+
d_x = 1
224+
d_y = 1
225+
err = d_x - (radius << 1)
226+
while x >= y:
227+
self.pixel(center_x + x, center_y + y, color)
228+
self.pixel(center_x + y, center_y + x, color)
229+
self.pixel(center_x - y, center_y + x, color)
230+
self.pixel(center_x - x, center_y + y, color)
231+
self.pixel(center_x - x, center_y - y, color)
232+
self.pixel(center_x - y, center_y - x, color)
233+
self.pixel(center_x + y, center_y - x, color)
234+
self.pixel(center_x + x, center_y - y, color)
235+
if err <= 0:
236+
y += 1
237+
err += d_y
238+
d_y += 2
239+
if err > 0:
240+
x -= 1
241+
d_x += 2
242+
err += d_x - (radius << 1)
243+
218244
def rect(self, x, y, width, height, color, *, fill=False):
219245
"""Draw a rectangle at the given location, size and color. The ```rect``` method draws only
220246
a 1 pixel outline."""

0 commit comments

Comments
 (0)