extmod/modframebuf: Add polygon drawing methods.

Add method for drawing polygons.

For non-filled polygons, uses the existing line-drawing code to render
arbitrary polygons using the given coords list, at the given x,y position,
in the given colour.

For filled polygons, arbitrary closed polygons are rendered using a fast
point-in-polygon algorithm to determine where the edges of the polygon lie
on each pixel row.

Tests and documentation updates are also included.

Signed-off-by: Mat Booth <mat.booth@gmail.com>
This commit is contained in:
Mat Booth
2022-07-13 21:09:51 +01:00
committed by Damien George
parent 42ec9703a0
commit 04a655c744
4 changed files with 931 additions and 2 deletions

View File

@@ -11,8 +11,8 @@ class FrameBuffer
-----------------
The FrameBuffer class provides a pixel buffer which can be drawn upon with
pixels, lines, rectangles, ellipses, text and even other FrameBuffers. It is
useful when generating output for displays.
pixels, lines, rectangles, ellipses, polygons, text and even other
FrameBuffers. It is useful when generating output for displays.
For example::
@@ -98,6 +98,17 @@ The following methods draw shapes onto the FrameBuffer.
to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 and b3 Q4. Quadrants
are numbered counterclockwise with Q1 being top right.
.. method:: FrameBuffer.poly(x, y, coords, c[, f])
Given a list of coordinates, draw an arbitrary (convex or concave) closed
polygon at the given x, y location using the given color.
The *coords* must be specified as a :mod:`array` of integers, e.g.
``array('h', [x0, y0, x1, y1, ... xn, yn])``.
The optional *f* parameter can be set to ``True`` to fill the polygon.
Otherwise just a one pixel outline is drawn.
Drawing text
------------