Drawing Paths

Using bezier paths.

newPath()

Create a new path.

moveTo(xy)

Move to a point x, y.

lineTo(xy)

Line to a point x, y.

curveTo(xy1, xy2, xy3)

Curve to a point x3, y3. With given bezier handles x1, y1 and x2, y2.

qCurveTo(*points)

Quadratic curve with a given set of off curves to a on curve.

arc(center, radius, startAngle, endAngle, clockwise)

Arc with center and a given radius, from startAngle to endAngle, going clockwise if clockwise is True and counter clockwise if clockwise is False.

arcTo(xy1, xy2, radius)

Arc from one point to an other point with a given radius.

closePath()

Close the path.

drawPath(path=None)

Draw the current path, or draw the provided path.

# create a new empty path
newPath()
# set the first oncurve point
moveTo((100, 100))
# line to from the previous point to a new point
lineTo((100, 900))
lineTo((900, 900))

# curve to a point with two given handles
curveTo((900, 500), (500, 100), (100, 100))

# close the path
closePath()
# draw the path
drawPath()
clipPath(path=None)

Use the given path as a clipping path, or the current path if no path was given.

Everything drawn after a clipPath() call will be clipped by the clipping path. To “undo” the clipping later, make sure you do the clipping inside a with savedState(): block, as shown in the example.

# create a bezier path
path = BezierPath()
# draw a triangle
# move to a point
path.moveTo((100, 100))
# line to a point
path.lineTo((100, 900))
path.lineTo((900, 900))
# close the path
path.closePath()
# save the graphics state so the clipping happens only
# temporarily
with savedState():
    # set the path as a clipping path
    clipPath(path)
    # the oval will be clipped inside the path
    oval(100, 100, 800, 800)
# no more clipping here