Circle and Curves

Learn to make circles and curves with Pycairo.

We'll cover the following...

Arcs

An arc is a part of the circumference of a circle. The arc function is called like this: ctx.arc(cx,cy,r,a1,a2)

The following image shows how these parameters are used to draw an arc:

The arc is part of a circle, with radius r and centered at the point (cx, cy). It starts at angle a1 and ends at angle a2. Angles are measured from the x-axis and, by default, increase as we move clockwise. Here is an example of the code used to draw an arc:

Press + to interact
import cairo
import math
# Set up pycairo
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 600, 400)
ctx = cairo.Context(surface)
ctx.set_source_rgb(0.8, 0.8, 0.8)
ctx.paint()
# Draw an arc
ctx.arc(300, 200, 150, 0, math.pi/2)
ctx.set_source_rgb(1, 0, 0)
ctx.set_line_width(10)
ctx.stroke()

Angles in ...