PyX — Example: drawing2/clipping.py

0.3 KB
6.2 KB
0.6 KB
1.0 KB

Clipping a canvas

clipping.png
from pyx import *

clippath = path.circle(0, 0, 1)
drawpath = path.line(-2, -2, 1.2, 2)

cl = canvas.canvas([canvas.clip(clippath)])
cl.stroke(drawpath, [color.rgb.red, style.linewidth(1.0)])

c = canvas.canvas()
c.stroke(drawpath, [style.linewidth(1.0)])
c.insert(cl)
c.stroke(clippath)

c.writeEPSfile("clipping")
c.writePDFfile("clipping")

Description

This example shows how drawing on a canvas can be clipped to a predefined region. The thick line is drawn two times, first in black onto an ordinary canvas, the second time in red onto a canvas which is clipped to the indicated circle.

The clipping property of a canvas must be specified on creation with an instance of canvas.clip, which takes a path as an argument. Note that this way of clipping will probably be removed in future releases of PyX. Instead, it will become part of the box concept.