%!PS-Adobe-2.0
%%Pages: 0 1
%%BoundingBox: 0 0 612 792
%%EndComments
% Note: two-thirds of the way down, change "fill" to "stroke"
% to get stroked braids.
% main 3 parameters, with default values
/m 7 def % number of poinst on star
/delta 0.34 def % width of "tape"
/space 0.06 def % gap as one tape goes over another
/alf 360 m div def % just angle between points, not a parameter
/r 100 def % scale factor
/inter { % stack: x1f y1f x2f y2f u1f v1f u2f v2f
% intersecting lines: (x-y, u-v) ,returns x and y coords of intersection point
/v2f exch def
/u2f exch def
/v1f exch def
/u1f exch def
/y2f exch def
/x2f exch def
/y1f exch def
/x1f exch def
x1f x2f sub abs 0.000001 lt {
/n v2f v1f sub u2f u1f sub div def
x1f % return xInter
n x1f mul v1f add n u1f mul sub % return yInter
} {
u1f u2f sub abs 0.000001 lt {
/mf y2f y1f sub x2f x1f sub div def
u1f % return xInter
mf u1f mul y1f add mf x1f mul sub % return yInter
} {
/mf y2f y1f sub x2f x1f sub div def
/n v2f v1f sub u2f u1f sub div def
v1f n u1f mul sub y1f sub mf x1f mul add mf n sub div %return xInter
mf v1f mul mf n mul u1f mul sub n y1f mul sub mf n mul x1f mul add
mf n sub div % return yInter
} ifelse
} ifelse
} def % inter
/calcxs { % calcxs: calculate coords for a lot of points
/t 1 delta sub def
/tp 1 space add def
/tq 1 delta sub space sub def
/x10 tq alf cos mul def
/y10 tq alf sin mul def
/x11 tq 3 alf mul cos mul def
/y11 tq 3 alf mul sin mul def
/x12 2 alf mul cos def
/y12 2 alf mul sin def
/x13 t 2 alf mul cos mul def
/y13 t 2 alf mul sin mul def
/x14 t 2 neg alf mul cos mul def
/y14 t 2 neg alf mul sin mul def
/x15 2 neg alf mul cos def
/y15 2 neg alf mul sin def
/x16 tp alf neg cos mul def
/y16 tp alf neg sin mul def
/x17 tp alf cos mul def
/y17 tp alf sin mul def
/x1 0 cos def
/y1 0 sin def
x10 y10 x11 y11 x1 y1 x12 y12 inter
/y2 exch def
/x2 exch def
/x4 t 0 cos mul def
/y4 t 0 sin mul def
x10 y10 x11 y11 x4 y4 x13 y13 inter
/y3 exch def
/x3 exch def
x4 y4 x14 y14 x16 y16 x17 y17 inter
/y5 exch def
/x5 exch def
x1 y1 x15 y15 x16 y16 x17 y17 inter
/y6 exch def
/x6 exch def
%% other delta calculation
1 0
2 alf mul cos 2 alf mul sin
alf cos alf sin
3 alf mul cos 3 alf mul sin
inter
/xSpec exch def
/ySpec exch def
/delta2 1 xSpec alf cos div sub space alf sin mul sub def
} def % calcxs
/drawPart { % draw one of m segments of star
newpath
x1 y1 moveto
x2 y2 lineto
x3 y3 lineto
x4 y4 lineto
x5 y5 lineto
x6 y6 lineto
closepath
fill % change to "stroke" to get stroked braids
} def % drawPart
/printStar { % stack: r space delta xCent yCent m
% draw all m segments of star, perhaps redefine parameters
/m exch def % number of points of star
/alf 360 m div def % just angle between points, not a parameter
/yCent exch def % y-coord of center of star
/xCent exch def % x-coord of center of star
/delta exch def % width of "tape"
/space exch def % gap as one tape goes over another
/r exch def % scale factor
calcxs
gsave
xCent yCent translate
r r scale
1 1 m { pop alf rotate drawPart } for
grestore
} def %printstar
% 1st star: maximum width of tape for a regular star
54 0.06 0.34 70 700 7 printStar
% 1st star, but larger
100 0.06 0.34 250 700 7 printStar
% 2nd star, narrower tape, with same gap
54 0.06 0.25 70 590 7 printStar
% Another star, but larger yet
125 0.03 0.18 460 600 7 printStar
% 1st star, but color red
0 1 1 0 setcmykcolor
54 0.06 0.34 70 480 7 printStar
% 3rd star, larger, color blue, narrower gap, narrower tape
1 1 0 0 setcmykcolor
80 0.04 0.25 250 520 7 printStar
% 8, 9, 10, 11, 12 points, different colors
1 0 1 0 setcmykcolor
54 0.05 0.2575 70 370 8 printStar
1 0 0 0 setcmykcolor
54 0.045 0.2 180 370 9 printStar
0 1 0 0 setcmykcolor
54 0.03 0.1667 290 370 10 printStar
0 0 1 0 setcmykcolor
54 0.025 0.142 400 370 11 printStar
0.5 0.5 1 0 setcmykcolor
54 0.025 0.1123 510 370 12 printStar
% Here tape width is set to impossible high value
1 0.5 1 0 setcmykcolor
54 0.04 0.72 70 260 7 printStar
1 0.5 0 0 setcmykcolor
54 0.035 0.556 180 260 8 printStar
0 1 0.5 0 setcmykcolor
54 0.03 0.44 290 260 9 printStar
0 0.5 1 0 setcmykcolor
54 0.025 0.36 400 260 10 printStar
0 0.5 0.5 0 setcmykcolor
54 0.02 0.3 510 260 11 printStar
showpage