%!PS-Adobe-2.0
%%Pages: 0 1
%%BoundingBox: 0 0 612 792
%%EndComments

/n 12 def % number of points on star
% use n = 14, 16, with changes in "points" function below
% n = 10, 18 require additional changes, not shown
/h 0.1 def %  distance between 6 loops and centerline
/whitestroke 0.10 def % width of wide while lines
/colorstroke 0.08 def % width of narrower colored lines
% use whitestroke = 0.09, colorstroke = 0.07 when n = 14
% use whitestroke = 0.08, colorstroke = 0.06 when n = 16
% any larger values (fatter red lines) end up with path interference

% use of white, then color creates white "gaps" along the way, width (0.1 - 0.08)/2
/th 360 n div def % angles in one segment of disk

% a few colors to use
/White {0 0 0 0 0 setcmykcolor}def
/Red {0 1 1 0 setcmykcolor}def
/Green {1 0 1 0 setcmykcolor}def
/Blue {1 1 0 0 setcmykcolor}def
/Yellow {0 0 1 0 setcmykcolor}def
/Cyan {1 0 0 0 setcmykcolor}def

% intersection point of two lines
/inter { % stack x1f y1f x2f y2f u1f v1f u2f v2f, two intersecting lines
   /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 {
      /nf v2f v1f sub u2f u1f sub div def
      x1f  % return xInter
      nf x1f mul v1f add nf 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
            /nf v2f v1f sub u2f u1f sub div def
            v1f nf u1f mul sub y1f sub mf x1f mul add mf nf sub div %return xInter
            mf v1f mul mf nf mul u1f mul sub nf y1f mul sub mf nf mul x1f mul add 
                mf nf sub div % return yInter
         } ifelse
   } ifelse
} def inter

% point a ratio r of the way from one point to another
/short { % stack: xf yf uf vf rf
         % (x,y) is 1st point, (u,v) is 2nd
         % returned on stack is (w,z), pt on line
         % r of the way from 1st to 2nd
   /rf exch def
   /vf exch def
   /uf exch def
   /yf exch def
   /xf exch def

   /wf xf rf uf xf sub mul add def
   wf % return x coord of pt on stack
   /zf yf rf vf yf sub mul add def
   zf % return y coord of pt on stack
} def % short

% points needed for drawing a 6th pie shape (if n = 12)
/points {
  /c0x 1 def % ci counterclockwise aroung circle, i >= 0
  /c0y 0 def
  /c1x th cos def
  /c1y th sin def
  /c2x th 2 mul cos def
  /c2y th 2 mul sin def
  /c3x th 3 mul cos def
  /c3y th 3 mul sin def
  /c4x th 4 mul cos def
  /c4y th 4 mul sin def
  /c5x th 5 mul cos def
  /c5y th 5 mul sin def
  /cm1x th neg cos def % cmi counterclockwise around circle, i < 0
  /cm1y th neg sin def
  /cm2x th 2 mul neg cos def
  /cm2y th 2 mul neg sin def
  /cm3x th 3 mul neg cos def
  /cm3y th 3 mul neg sin def
  % from here on, must draw picture carefully
  % d1 is inter (c1 - c5, 0 - c2)
  c1x c1y c5x c5y 0 0 c2x c2y inter
    /d1y exch def
    /d1x exch def
  % d2 is inter (c1 - cm3, 0 - c0)
  c1x c1y cm3x cm3y 0 0 c0x c0y inter
    /d2y exch def
    /d2x exch def
  /f0x c2x def
  /f0y 0 def
  % d3 is inter (c2 - f0, (0,h) - (1,h))
  c2x c2y f0x f0y 0 h 1 h inter
    /d3y exch def
    /d3x exch def
  % d4 is inter (0 - c2, (0,h) - (1,h))
  0 0 c2x c2y 0 h 1 h inter
    /d4y exch def
    /d4x exch def
  /d5x h th 2 mul sin div def % point closest to origin
  /d5y 0 def
  /f1x c2x def
  /f1y c2y h 90 th 2 mul sub sin div sub def
  % d6 is inter (d5 - f1, c0 - c4), vertex of small quadrilateral
    d5x d5y f1x f1y c0x c0y c4x c4y inter
    /d6y exch def
    /d6x exch def
  /d7x d6x def % 4th vertex of quadrilateral
  /d7y d6y neg def

  % new points related to fancier approach
  d3x d3y c2x c2y 0.88 short % 0.88 for n=12, 0.9 for n=14,16
    /e1y exch def
    /e1x exch def
  c1x c1y d1x d1y 0.9 short
    /e3y exch def
    /e3x exch def
  d3x d3y d4x d4y 0.925 short
    /e2y exch def
    /e2x exch def
  cm1x cm1y d2x d2y 0.9 short
    /g3y exch def
    /g3x exch def
  d7x d7y c0x c0y 0.88 short % 0.88 for n=12, 0.9 for n=14,16
    /g1y exch def
    /g1x exch def
  d7x d7y d5x d5y 0.925 short
    /g2y exch def
    /g2x exch def
  c2x c2y d3x d3y 0.6 short % 0.6 for n=12, 0.55 for n=14, 0.5 for n=16
    /h1y exch def
    /h1x exch def
  d5x d5y d6x d6y 0.5 short
    /h2y exch def
    /h2x exch def
} def % points

% carry out entire drawing
/everything{

points

/paths {
% now paths in one segment of disc
% for n = 12, can't get much fatter than this

  % use other strokesi functions for more colors
  /strokes1 {
    gsave
      White
      whitestroke setlinewidth
    stroke % stroke wide white line
    grestore
    Red
    colorstroke setlinewidth
    stroke % narrower colored line, to leave white "gaps"
  } def strokes1

  /strokes2 {
    gsave
      White
      whitestroke setlinewidth
      stroke
    grestore
    Green
    colorstroke setlinewidth
    stroke
  } def strokes2

 % need 5 paths because of order of crossings
 % separate paths are attached exactly, but the picture
 % ends up with tiny wide lines at the connection points
 % of width "zero".  They are visible, but get no bigger under magnification
 % path 1
 newpath
  e1x e1y moveto
  h1x h1y lineto
  strokes2

 % path 2, creates the entire 6-pointed star
 newpath
  e3x e3y moveto
  c1x c1y lineto
  d2x d2y lineto
  g3x g3y lineto
  strokes1

 % path 3
 newpath
  g1x g1y moveto
  c0x c0y lineto
  d6x d6y lineto
  h2x h2y lineto
  strokes2

 % path 4
 newpath
  h1x h1y moveto
  d3x d3y lineto
  e2x e2y lineto
  strokes2

 % path 5
 newpath
  h2x h2y moveto
  d5x d5y lineto
  g2x g2y lineto
  strokes2
} def % paths

 % loop through each sector of disk
 % iterate n/2 times
 1 1 n 2 div {
   paths
    360 2 mul n div rotate
 } for

} def % everything

200 200 scale % original circle radius = 1
1.5 1.5 translate
everything

showpage