CS 3723/3721
Programming Languages

Paths and Clipping
(+ Colors)


Examples Using Paths and Clipping Paths: Examples 4 through Example 11 below give increasingly complex pictures using clipping paths.

Paths and Clipping Paths
%!PS-Adobe-2.0
% Example 1
/Mulberry {0.34 0.90 0 0.02 setcmykcolor} def
/oneline {
  0 0 moveto 450 0 lineto stroke
} def

/lines {
  gsave
    oneline
    180 {1 rotate oneline} repeat
  grestore
} def

200 100 translate
1 setlinewidth
lines
showpage
%!PS-Adobe-2.0
% Example 2
/Mulberry {0.34 0.90 0 0.02 setcmykcolor} def
/circle {
  newpath
   0 0 100 0 360 arc
  closepath
} def

200 200 translate
Mulberry circle fill
0 setgray
2 setlinewidth
circle stroke
showpage

%!PS-Adobe-2.0
% Example 3
/Mulberry {0.34 0.90 0 0.02 setcmykcolor} def
/oneline {
  0 0 moveto 450 0 lineto stroke
} def

/lines {
  gsave
    oneline
    180 {1 rotate oneline} repeat
  grestore
} def

/circle {
  newpath
   0 100 100 0 360 arc
  closepath
} def

200 100 translate
Mulberry circle fill
0 setgray
2 setlinewidth
circle stroke
1 setlinewidth
lines
showpage
%!PS-Adobe-2.0
% Example 4
/oneline {
  0 0 moveto 450 0 lineto stroke
} def

/lines {
  gsave
    oneline
    180 {1 rotate oneline} repeat
  grestore
} def

/circle {
  newpath
   0 100 100 0 360 arc
  closepath
} def

200 100 translate
Mulberry circle fill
0 setgray
2 setlinewidth
circle stroke

circle clip
1 setlinewidth
lines
showpage
%!PS-Adobe-2.0
% Example 5
/Mulberry {0.34 0.90 0 0.02 setcmykcolor} def
/oneline {
  0 0 moveto 550 0 lineto stroke
} def

/lines {
  gsave
    oneline
    180 {1 rotate oneline} repeat
  grestore
} def

/path {
  /Times-Bold findfont 250 scalefont setfont
  newpath 0 0 moveto (ABC) false charpath
} def

50 100 translate
Mulberry path fill
0 setgray
2 setlinewidth
path stroke

path clip
1 setlinewidth
lines
showpage
%!PS-Adobe-2.0
% Example 6
% Some colors
/Apricot{0 0.32 0.52 0 setcmykcolor} def
/OliveGreen{0.64 0 0.95 0.40 setcmykcolor} def
/GreenYellow{0.15 0 0.69 0 setcmykcolor} def
/RedViolet{0.07 0.90 0 0.34 setcmykcolor} def
/Times-Bold findfont 80 scalefont setfont

/background {
   newpath
   0 0 moveto
   1000 0 lineto
   1000 1000 lineto
   0 1000 lineto
   closepath
} def

/pl {
   50 200 moveto
   (Programming) show
   50 100 moveto
   (Languages) show
} def

/circle {
  newpath
   250 175 130 0 360 arc
  closepath
} def

Apricot background fill
OliveGreen pl
  
circle clip
GreenYellow background fill
RedViolet pl 
showpage
% Example 6.1
% with the line "circle clip" commented out
%!PS-Adobe-2.0
% Example 7
/Apricot{0 0.32 0.52 0 setcmykcolor} def
/OliveGreen{0.64 0 0.95 0.40 setcmykcolor} def
/GreenYellow{0.15 0 0.69 0 setcmykcolor} def
/RedViolet{0.07 0.90 0 0.34 setcmykcolor} def
/Times-Bold findfont 80 scalefont setfont

/background {
   newpath
   0 0 moveto
   1000 0 lineto
   1000 1000 lineto
   0 1000 lineto
   closepath
} def

/pl {
   50 200 moveto
   (Programming) show
   50 100 moveto
   (Languages) show
} def

/circles {
  newpath
   435 50 2 div add 230 50 2 div add moveto
     435 230 50 0 360 arc
   250 130 2 div add 175 130 2 div add moveto
     250 175 130 0 360 arc
   230 60 2 div add 155 602 2 div add moveto
     230 155 60 0 360 arc
  closepath
} def

Apricot background fill
OliveGreen pl
  
circles eoclip % even-odd clipping algorithm
GreenYellow background fill
RedViolet pl 
showpage

Example  9 Example 10 Example 11
%!PS-Adobe-2.0
% Example 8
/Apricot{0 0.32 0.52 0 setcmykcolor} def
/OliveGreen{0.64 0 0.95 0.40 setcmykcolor} def
/GreenYellow{0.15 0 0.69 0 setcmykcolor} def
/RedViolet{0.07 0.90 0 0.34 setcmykcolor} def
/Times-Bold findfont 110 scalefont setfont

/background {
   newpath
   0 0 moveto
   1000 0 lineto
   1000 1000 lineto
   0 1000 lineto
   closepath
} def

/pl {
   50 200 moveto
   (Programming) show
   50 100 moveto
   (Languages) show
} def

/circlepath { % stack: x y r
  /r exch def  /y exch def  /x exch def
  x r 2 div add y r 2 div add moveto
     x y r 0 360 arc
} def

/circles {
  newpath
    500 230 65 circlepath
    250 175 130 circlepath
    230 155 60 circlepath
    475 160 65 circlepath
  closepath
} def

/everything {
Apricot background fill
OliveGreen pl
  
circles eoclip % even-odd clipping algorithm
GreenYellow background fill
RedViolet pl 
} def

% below to keep vert. alignment, < 5 no good
5 { 1000 1000 moveto (abcdefgh) show} repeat

90 rotate
0 -612 translate
everything
showpage


Examples of Colors: In alphabetic order by name, but random order as far as the type of color.

List of Colors
/Apricot{0 0.32 0.52 0 setcmykcolor} def
/Aquamarine{0.82 0 0.30 0 setcmykcolor} def
/Bittersweet{0 0.75 1 0.24 setcmykcolor} def
/Black{0 0 0 1 setcmykcolor} def
/Blue{1 1 0 0 setcmykcolor} def
/BlueGreen{0.85 0 0.33 0 setcmykcolor} def
/BlueViolet{0.86 0.91 0 0.04 setcmykcolor} def
/BrickRed{0 0.89 0.94 0.28 setcmykcolor} def
/Brown{0 0.81 1 0.60 setcmykcolor} def
/BurntOrange{0 0.51 1 0 setcmykcolor} def
/CadetBlue{0.62 0.57 0.23 0 setcmykcolor} def
/CarnationPink{0 0.63 0 0 setcmykcolor} def
/Cerulean{0.94 0.11 0 0 setcmykcolor} def
/CornflowerBlue{0.65 0.13 0 0 setcmykcolor} def
/Cyan{1 0 0 0 setcmykcolor} def
/Dandelion{0 0.29 0.84 0 setcmykcolor} def
/DarkOrchid{0.40 0.80 0.20 0 setcmykcolor} def
/Emerald{1 0 0.50 0 setcmykcolor} def
/ForestGreen{0.91 0 0.88 0.12 setcmykcolor} def
/Fuchsia{0.47 0.91 0 0.08 setcmykcolor} def
/Goldenrod{0 0.10 0.84 0 setcmykcolor} def
/Gray{0 0 0 0.50 setcmykcolor} def
/Green{1 0 1 0 setcmykcolor} def
/GreenYellow{0.15 0 0.69 0 setcmykcolor} def
/JungleGreen{0.99 0 0.52 0 setcmykcolor} def
/Lavender{0 0.48 0 0 setcmykcolor} def
/LimeGreen{0.50 0 1 0 setcmykcolor} def
/Magenta{0 1 0 0 setcmykcolor} def
/Mahogany{0 0.85 0.87 0.35 setcmykcolor} def
/Maroon{0 0.87 0.68 0.32 setcmykcolor} def
/Melon{0 0.46 0.50 0 setcmykcolor} def
/MidnightBlue{0.98 0.13 0 0.43 setcmykcolor} def
/Mulberry{0.34 0.90 0 0.02 setcmykcolor} def
/NavyBlue{0.94 0.54 0 0 setcmykcolor} def
/OliveGreen{0.64 0 0.95 0.40 setcmykcolor} def
/Orange{0 0.61 0.87 0 setcmykcolor} def
/OrangeRed{0 1 0.50 0 setcmykcolor} def
/Orchid{0.32 0.64 0 0 setcmykcolor} def
/Peach{0 0.50 0.70 0 setcmykcolor} def
/Periwinkle{0.57 0.55 0 0 setcmykcolor} def
/PineGreen{0.92 0 0.59 0.25 setcmykcolor} def
/Plum{0.50 1 0 0 setcmykcolor} def
/ProcessBlue{0.96 0 0 0 setcmykcolor} def
/Purple{0.45 0.86 0 0 setcmykcolor} def
/RawSienna{0 0.72 1 0.45 setcmykcolor} def
/Red{0 1 1 0 setcmykcolor} def
/RedOrange{0 0.77 0.87 0 setcmykcolor} def
/RedViolet{0.07 0.90 0 0.34 setcmykcolor} def
/Rhodamine{0 0.82 0 0 setcmykcolor} def
/RoyalBlue{1 0.50 0 0 setcmykcolor} def
/RoyalPurple{0.75 0.90 0 0 setcmykcolor} def
/RubineRed{0 1 0.13 0 setcmykcolor} def
/Salmon{0 0.53 0.38 0 setcmykcolor} def
/SeaGreen{0.69 0 0.50 0 setcmykcolor} def
/Sepia{0 0.83 1 0.70 setcmykcolor} def
/SkyBlue{0.62 0 0.12 0 setcmykcolor} def
/SpringGreen{0.26 0 0.76 0 setcmykcolor} def
/Tan{0.14 0.42 0.56 0 setcmykcolor} def
/TealBlue{0.86 0 0.34 0.02 setcmykcolor} def
/Thistle{0.12 0.59 0 0 setcmykcolor} def
/Turquoise{0.85 0 0.20 0 setcmykcolor} def
/Violet{0.79 0.88 0 0 setcmykcolor} def
/VioletRed{0 0.81 0 0 setcmykcolor} def
/White{0 0 0 0 setcmykcolor} def
/WildStrawberry{0 0.96 0.39 0 setcmykcolor} def
/Yellow{0 0 1 0 setcmykcolor} def
/YellowGreen{0.44 0 0.74 0 setcmykcolor} def
/YellowOrange{0 0.42 1 0 setcmykcolor} def


Display of Each Color Above:

Click Image for PDF, or click link for larger image (.png)

(Revision date: 2014-04-12. Please use ISO 8601, the International Standard.)