RedGrittyBrick

Drawing graduated colour fills in Postscript

Normal Fill

Image Flat colour renders quickly.

Postscript

%
% draw shape 
%
1 inch 1 inch moveto
2 inch 1 inch lineto
2.5 inch 1 inch 0.5 inch 180 0 arc
4 inch 1 inch lineto
4 inch 2 inch lineto
3.2 inch 2 inch 3 inch 3 inch 2.5 inch 
         3 inch curveto 
2 inch 3 inch 1.8 inch 2 inch 1 inch 
         2 inch curveto
closepath
%
% fill
%
gsave % save path for re-use
0.12 1 1 sethsbcolor
fill
grestore % restore path
%
% draw outline of restored path
%
3 setlinewidth
0 0 0 setrgbcolor
stroke

download

Graduated fill

Image A graduated fill renders slowly.

Postscript code

%
% draw shape 
%
1 inch 1 inch moveto
2 inch 1 inch lineto
2.5 inch 1 inch 0.5 inch 180 0 arc
4 inch 1 inch lineto
4 inch 2 inch lineto
3.2 inch 2 inch 3 inch 3 inch 2.5 inch 
         3 inch curveto 
2 inch 3 inch 1.8 inch 2 inch 1 inch 
       2 inch curveto
closepath
%
% fill
%
gsave % save path for re-use
clip % set path as clipping path for infill
3.5 inch 0.5 inch translate % origin bot rt
45 rotate % so fill is diagonal
Step setlinewidth
/s 3 inch def
0.05 1.0 0.8 StartHSB 
0.19 1.0 1.0 EndHSB 
1 Step s {
StepHSB
newpath
-2 inch exch moveto % position left side
4 inch 0 rlineto % draw a line
stroke
} for
grestore % restore path
%
% draw outline of restored path
%
3 setlinewidth
0 0 0 setrgbcolor
stroke

Postscript function

% 
% functions 
% 
/inch { 72 mul } def 
/dpi { 72 div } def 
/Rez 150 dpi def % calc lines per pt for fill 
/Step 1 Rez div def 
/StartHSB { /B1 exch def /S1 exch def 
            /H1 exch def } def 
/EndHSB { /B2 exch def /S2 exch def 
            /H2 exch def 
/Steps s Step div def 
/Hstep H2 H1 sub Steps div def 
/Sstep S2 S1 sub Steps div def 
/Bstep B2 B1 sub Steps div def 
} def 
/StepHSB { /H1 H1 Hstep add def 
/S1 S1 Sstep add def 
/B1 B1 Bstep add def 
H1 S1 B1 sethsbcolor 
} def 

download