Extending Drawing Functions
Although there are a number of drawing functions available in most of the standard graphics libraries, most of them lack some basic shapes such as a circle. To draw circles on your display, you will need to add your own Python functions. Here are some examples of these custom drawing functions.
If we assume we have a 64x128 display we can call two circle functions to draw eyes
display.fill(0) # Clear the display. display.circle(32, 32, 10, 1) # draw the left eye
Here are the parameters for circle functions
- X position of the circle center
- Y position of the circle center
- Radius of the circle in pixels
- The color of the drawing, 1 for on and 0 for off.
This similar to the circle, but pixels internal to the circle are filled.
For each pixel in the "square" bounding box that surrounds the circle, we need to do a little math to see if the pixel is inside or outside of the circle.
1 2 3 4 5
Now all we need to do is write a function called in_circle() to turn the pixel on. We can use some basic geometry to see if a point at x,y is within the radius by using the distance function.
distance = sqrt(xx + yy)
1 2 3 4 5 6