Open and Closed Shapes
Get introduced to open and closed shapes with Pycairo.
We'll cover the following...
In the previous lessons, we used the rectangle
function. Generally, though, if we need to create any other type of shape, we construct it with separate lines and curves. Let’s start by drawing a simple straight line. Here is how a line is drawn on a surface:
Lines
Pycairo uses the idea of a current point when drawing shapes. This makes it easy to create common shapes, such as polygons, which are formed through the end-to-end joining of lines or curves.
Press + to interact
import cairo# Set up surfacesurface = cairo.ImageSurface(cairo.FORMAT_RGB24, 600, 400)ctx = cairo.Context(surface)ctx.set_source_rgb(0.8, 0.8, 0.8)ctx.paint()# Draw a linectx.move_to(100, 100)ctx.line_to(500, 300)ctx.set_source_rgb(1, 0, 0)ctx.set_line_width(10)ctx.stroke()
...