fibonacci stage 1 spiral

%! /buf 50 string def /unit 12 def /box { % argument is fibb (n) i.e. scale factor for boxsize /fval exch def %/nval exch def /fval fval 0 eq {1} {fval} ifelse def /side fval unit mul def gsave /disp fval 2 div round def /psize disp 6 add def /Helvetica findfont psize scalefont setfont %disp disp moveto %/angle nval 90 mul neg def %angle rotate %/newx angle neg dup cos disp mul exch sin disp mul sub def %/newy angle neg dup cos disp mul exch sin disp mul add def %newx newy moveto %fval buf cvs show grestore %angle neg rotate 0 0 moveto side 0 rlineto 0 side rlineto side neg 0 rlineto 0 side neg rlineto % we should now be back at the origin %draw the arc 0 0 side 0 90 arc } def /shade { unit 9 mul unit 6 neg mul moveto 0 setgray 0 1 90 { dup /x exch cos 34 mul unit mul def /y exch sin 34 mul unit mul def x y lineto unit 9 mul unit 6 neg mul moveto %0 0 moveto } for } def /spiralfibb { 10 dict begin /n exch def n n 1 lt exch 10 gt or {(Incoming argument for fibb out of range\n) print quit} if %If value of n is one call up box and then push 0 and 1 onto stack and return, n 1 eq { %pop 0 box 0 1 } { %subtract 1 from i value at top of stack for next recursive % call to spiralfibb i.e. a call of spiralfibb(i-1) n 1 sub spiralfibb % now pick up two values returned on stack from level below and manipulate them dup 3 1 roll exch dup /oldf exch def add dup /f exch def 90 rotate oldf unit mul neg 0 translate f box % now do the text %0 0 moveto %/disp f 2 div round def %/psize disp 6 add def %/Helvetica findfont psize scalefont setfont %disp disp moveto %oldf unit mul neg 0 translate %/angle nval 90 mul neg def %angle rotate %-90 rotate %oldf unit mul translate } ifelse end } def /Helvetica findfont 12 scalefont setfont /str 10 string def /startx 250 def /starty 250 def startx starty translate 0 0 moveto 1 setlinewidth %72 72 scale %1 box %0 0 unit 0 90 arc %90 rotate %0 0 translate %1 box %0 0 unit 0 90 arc %90 rotate %unit neg 0 translate %2 box %0 0 unit 2 mul 0 90 arc %90 rotate %unit neg 0 translate %3 box %0 0 unit 3 mul 0 90 arc %90 rotate %unit 2 mul neg 0 translate %5 box %90 rotate %unit 3 mul neg 0 translate %8 box %90 rotate %unit 5 mul neg 0 translate %13 box %90 rotate %unit 8 mul neg 0 translate %21 box %90 rotate %unit 13 mul neg 0 translate %34 box 9 spiralfibb 200 430 moveto (STAGE I) show stroke showpage

1 Response

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.