From c9d695e1f85cdcfeae11255bb4057c0abdbcaf27 Mon Sep 17 00:00:00 2001 From: boo 13 Date: Tue, 22 Oct 2019 13:43:28 -0400 Subject: [PATCH 1/2] Add ability to draw circle --- adafruit_framebuf.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 8b2e947..23e12e6 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -215,6 +215,32 @@ def vline(self, x, y, height, color): """Draw a vertical line up to a given length.""" self.rect(x, y, 1, height, color, fill=True) + def circle(self, center_x, center_y, radius, color): + """Draw a circle at the given midpoint location, radius and color. The ```circle``` method draws only + a 1 pixel outline.""" + x = radius - 1 + y = 0 + d_x = 1 + d_y = 1 + err = d_x - (radius << 1) + while x >= y: + self.pixel(center_x + x, center_y + y, color) + self.pixel(center_x + y, center_y + x, color) + self.pixel(center_x - y, center_y + x, color) + self.pixel(center_x - x, center_y + y, color) + self.pixel(center_x - x, center_y - y, color) + self.pixel(center_x - y, center_y - x, color) + self.pixel(center_x + y, center_y - x, color) + self.pixel(center_x + x, center_y - y, color) + if err <= 0: + y += 1 + err += d_y + d_y += 2 + if err > 0: + x -= 1 + d_x += 2 + err += d_x - (radius << 1) + def rect(self, x, y, width, height, color, *, fill=False): """Draw a rectangle at the given location, size and color. The ```rect``` method draws only a 1 pixel outline.""" From cede4f47ad8c4e86b72458c23965062963f11f56 Mon Sep 17 00:00:00 2001 From: boo 13 Date: Tue, 22 Oct 2019 14:59:02 -0400 Subject: [PATCH 2/2] Shorten comment line length --- adafruit_framebuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 23e12e6..9fbad45 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -216,8 +216,8 @@ def vline(self, x, y, height, color): self.rect(x, y, 1, height, color, fill=True) def circle(self, center_x, center_y, radius, color): - """Draw a circle at the given midpoint location, radius and color. The ```circle``` method draws only - a 1 pixel outline.""" + """Draw a circle at the given midpoint location, radius and color. + The ```circle``` method draws only a 1 pixel outline.""" x = radius - 1 y = 0 d_x = 1