Drawing Paths

Using bezier paths.


Create a new path.


Move to a point x, y.


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.


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.

pt0 = 74, 48
pt1 = 238, 182
pt2 = 46, 252
radius = 60

def drawPt(pos, r=5):
    x, y = pos
    oval(x-r, y-r, r*2, r*2)

size(300, 300)

path = BezierPath()
path.arcTo(pt1, pt2, radius)

stroke(0, 1, 1)
polygon(pt0, pt1, pt2)
for pt in [pt0, pt1, pt2]:

stroke(0, 0, 1)
stroke(1, 0, 1)
for pt in path.onCurvePoints:
    drawPt(pt, r=3)
for pt in path.offCurvePoints:
    drawPt(pt, r=2)

Close the path.


Draw the current path, or draw the provided path.

# create a new empty path
# 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
# draw the path

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
# save the graphics state so the clipping happens only
# temporarily
with savedState():
    # set the path as a clipping path
    # the oval will be clipped inside the path
    oval(100, 100, 800, 800)
# no more clipping here