Checkerboards
I wanted to draw checkerboards in Python Turtle. To get a filled polygon in Turtle, it has to be drawn entirely in one go as a closed shape. The common type of checkerboards are rectangular (or square). These are pretty straightforward to draw.
Here is an output of a rectangular checkerboard:
Here is the code to draw the output shown above:
Note: You can run, edit and make your own changes to all the code samples in this post and try them out (thanks to trinket).
Circular
Now that we have a rectangular checkerboard, I wanted to draw circular checkerboards. This involves the use of Turtle's circle method itself (with extent parameter set) to draw individual arcs. Each individual polygon can be considered as a quad with four points. These are calculated and connected using lines and arcs.
Here is an output of a circular checkerboard:
Here is the code for the circular checkerboard shown above:
Polygonal
After that, I wondered if we could draw checkerboards for any given polygon.
This is what I had in mind:
This is what I had in mind:
Expected polygon checkerboard |
This too involves drawing separate quads filled alternatively as with the circular checkerboard. The difference here is that the sides are straight lines instead of curves with a fixed radius. We move the Turtle to calculate these four points and then connect them.
Here are some outputs of checkerboards for different polygons:
Polygonal curved
I now wondered if we could draw curved lines at the sides instead of straight lines. I wanted to see how this looked for different polygons.
I extended the code for the polygon checkerboards to draw the curved ones. The basic idea is the same, but instead of straight lines, we have to use arcs to draw individual quads. To draw the arcs correctly, I had to remember and use the correct Turtle direction (heading) while connecting the four points.
Here are some outputs of curved checkerboards for different polygons:
Polygon checkerboard curved - Triangle |
|
Polygon checkerboard curved - Hexagon |
Other board patterns
Instead of a full curve (or straight lines) if you connect the points in different ways (red in the picture below) you can get different board patterns. We could potentially draw checkerboards for these too with a bit more work (future).
Here are some of these board patterns:
Here are some of these board patterns:
Spirals
The circular checkerboards can be easily extended to connect the four points of the quad in several different ways. Doing so, we can get interesting spirals.
Here are some sample spiral checkerboards that we can get by making small changes to the circular checkerboard code:
Spiral checkerboards |
Summary
In summary, checkerboards need not be only rectangular or circular, but any regular polygon - even curved, as shown above.
All the code in this post is available on GitHub.
Updates:
5 July 2020