Minustar
Minustar

Reputation: 1225

PostScript Path Combine

I have just begun learning PostScript in order to produce graphics for LaTeX and I have no idea how to combine a path with itself so the stroke only affect the outer border of the drawn shape. My code is as follows:

/black { 0 0 0 1 setcmykcolor } def
/gold { 0.02 0.17 0.72 0.05 setcmykcolor } def
newpath
  % the center is 1/2w and 1/2h
  /cx { 1200 2.0 div } def % center-x
  /cy {  600 2.0 div } def % center-y
  /r  {  600 9.0 div
               4 mul
             2.0 div } def % star's radius
  cx r   0 cos mul add
  cy r   0 sin mul add moveto
  cx r 144 cos mul add
  cy r 144 sin mul add lineto
  cx r 288 cos mul add
  cy r 288 sin mul add lineto
  cx r  72 cos mul add
  cy r  72 sin mul add lineto
  cx r 216 cos mul add
  cy r 216 sin mul add lineto
closepath
gsave
gold fill
grestore
1 setlinewidth
black stroke

When the stroke is drawn, the lines crossing the shape are drawn. I would like to know if there is a way to only have the outer border of the shape stricken and not the inner lines. i would rather not have to calculate where the lines forming the star intersect, i.e. keep 5 lines instead of getting 10 smaller ones.

Note also, that I am learning PS as-is and am not wanting to use external programs (read Illustrator and the like). The purpose of this question is to built up my knowledge of PostScript.

Upvotes: 2

Views: 668

Answers (2)

jdaw1
jdaw1

Reputation: 251

PostScript is missing an anticlip operator, which should restrict painting to outside the current path. There is clip, which restricts painting to inside, but that doesn’t help with this problem.

As previously suggested, you could stroke at double linewidth, and then fill white, but if you want to paint this on top of something else, that strategy obscures whatever is below.

Or you could make the star a little bigger (I suspect, but haven’t checked, by currentlinewidth 2 5 sqrt 2 mul 5 div add sqrt mul 2 div), but that would only look right if 1 setlinejoin.

Upvotes: 1

luser droog
luser droog

Reputation: 19504

Simplest would be to do the stroke first and then the fill. You may want to double your linewidth as doing this effectively cuts the lines in half.

%...
closepath
gsave
  2 setlinewidth
  black stroke
grestore
gold fill

Upvotes: 4

Related Questions