How to make pictures using postscript programs (part 8) ----------------------------------------------------------------------------- Another part of the current graphics state is the clipping region. The clipping region is where your drawing commands are actually executed; every part of your picture that falls outside the clipping region is not displayed. Initially, the clipping region is the entire plane (or perhaps the bounding box), and you can make it smaller by the command clip. clip takes your current path, which must be closed, like fill, and establishes that as new clipping path. Each further restriction of the clipping region makes it smaller, so additional clipping regions are intersected with the previous clipping region. If you need to go back to a larger clipping region, you have to save it, with gsave, and the restore it when needed. The previous clipping region is not moved by later coordinate transformations, it describes a fixed region on paper. ------------------------Example 16------------------------------------------- %!PS-Adobe-2.0 %%BoundingBox: 0 0 400 400 newpath 200 200 170 0 360 arc closepath clip %clips the following to a circle 0 4 400 {newpath 0 0 moveto 400 0 lineto stroke 0 4 translate} for showpage ------------------------Example 17------------------------------------------- %!PS-Adobe-2.0 %%BoundingBox: 0 0 300 200 gsave 50 50 translate newpath 0 0 moveto 100 0 lineto 100 100 lineto 0 100 lineto closepath clip %clips the following to a square 0 4 200 {newpath -100 0 moveto 100 100 rlineto stroke %Diagonal / 4 0 translate} for grestore gsave 150 50 translate newpath 0 0 moveto 100 0 lineto 100 100 lineto 0 100 lineto closepath clip %clips the following to a square 0 4 200 {newpath 0 0 moveto -100 100 rlineto stroke %Diagonal \ 4 0 translate} for grestore showpage ------------------------Example 18------------------------------------------- %!PS-Adobe-2.0 %%BoundingBox: 0 0 300 300 /petal {gsave newpath 100 0 moveto 50 -86.6 100 60 120 arc 50 86.6 100 240 300 arc closepath gsave stroke grestore clip 1.0 -0.1 0 {/c exch def newpath 0 -50 moveto 0 50 lineto 100 c mul 50 lineto 100 c mul -50 lineto closepath 1.0 c 0.1 setrgbcolor fill} for grestore } def 150 150 translate 1 1 6 {petal 60 rotate} for showpage