summaryrefslogtreecommitdiff
path: root/tests/extmod/framebuf_ellipse.py
diff options
context:
space:
mode:
authorPeter Hinch <peter@hinch.me.uk>2022-08-10 14:51:19 +0100
committerDamien George <damien@micropython.org>2022-08-19 23:31:28 +1000
commit42ec9703a07d1d0b55091f5557ff5f81c5134fb8 (patch)
tree374b5e1fe203469be8e020761ccfe047d8547d18 /tests/extmod/framebuf_ellipse.py
parent127b340438cddd55748e066cacbc1ab64131e232 (diff)
extmod/modframebuf: Add ellipse drawing method.
Diffstat (limited to 'tests/extmod/framebuf_ellipse.py')
-rw-r--r--tests/extmod/framebuf_ellipse.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/extmod/framebuf_ellipse.py b/tests/extmod/framebuf_ellipse.py
new file mode 100644
index 000000000..a4c784aff
--- /dev/null
+++ b/tests/extmod/framebuf_ellipse.py
@@ -0,0 +1,65 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+
+def printbuf():
+ print("--8<--")
+ for y in range(h):
+ for x in range(w):
+ print("%02x" % buf[(x + y * w)], end="")
+ print()
+ print("-->8--")
+
+
+w = 30
+h = 30
+buf = bytearray(w * h)
+fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS8)
+
+# Outline
+fbuf.fill(0)
+fbuf.ellipse(15, 15, 12, 6, 0xFF, False)
+printbuf()
+
+# Fill
+fbuf.fill(0)
+fbuf.ellipse(15, 15, 6, 12, 0xAA, True)
+printbuf()
+
+# Outline and fill some different quadrant combos.
+for m in (0, 0b0001, 0b0010, 0b0100, 0b1000, 0b1010):
+ fbuf.fill(0)
+ fbuf.ellipse(15, 15, 6, 12, 0xAA, False, m)
+ printbuf()
+ fbuf.fill(0)
+ fbuf.ellipse(15, 15, 6, 12, 0xAA, True, m)
+ printbuf()
+
+# Draw ellipses that will go out of bounds at each of the edges.
+for x, y in (
+ (
+ 4,
+ 4,
+ ),
+ (
+ 26,
+ 4,
+ ),
+ (
+ 26,
+ 26,
+ ),
+ (
+ 4,
+ 26,
+ ),
+):
+ fbuf.fill(0)
+ fbuf.ellipse(x, y, 6, 12, 0xAA, False)
+ printbuf()
+ fbuf.fill(0)
+ fbuf.ellipse(x, y, 6, 12, 0xAA, True)
+ printbuf()