home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / ps / easter2.zoo / easter2
Text File  |  1990-04-14  |  10KB  |  330 lines

  1.  
  2. %!
  3. %Just in case anyone has an idle printer I am posting a close replication of 
  4. %"Square-limit" by M.C.Escher.  I have called it "Square-recursion" because it
  5. %builds the image by recursion, following the triangle subdivision used by 
  6. %Escher.
  7. %
  8. %I have used Postscript graphics to the full, using transformations and curves
  9. %freely. However it takes a long time to run as a result.  The version posted
  10. %has a variable "Maxlevel", which defaults to 0, and takes 2 minutes to
  11. %produce a core picture.  Try that first, and check that all is well,  then
  12. %if you wish the full gory detail set Maxlevel to 3, and wait 25 minutes (on
  13. %an Apple laser writer)
  14. %
  15. %> 2 min 10 seconds on a RIPS at 400 dpi
  16. %> comment added 7/89 by Ross Smith, PC Publishing.
  17. %
  18. %Any tips on improving the run time would be welcome.  Have fun.
  19. %
  20. %John M Pratt,
  21. %European Computer-industry Research Centre,
  22. %Arabellastrasse 17,
  23. %D 8000 Munich 81,
  24. %West Germany.
  25. %
  26. %email-   harry%ecrcvax.UUCP@Germany.CSNET
  27. %
  28. %-----------Cut Here----------------------
  29. %!PS-Adobe-1.0
  30. %%Title:Square-recursion
  31. %%DocumentFonts: (atend)
  32. %%Creator: John Pratt and M.C.Escher 
  33. %%CreationDate:25 November 1987 
  34. %%Pages: (atend)
  35. %%EndComments
  36.  
  37. %%EndProlog
  38.  
  39. %%Page: 1 1 
  40. /Helvetica-Bold findfont 0.5 scalefont setfont 
  41. /level 0 def                %control variable for recursion
  42. /maxlevel 0 def                %Limit of recursion, 3 takes 25 min. 
  43. /Down { /level level 1 add def }def
  44. /Up {/level level 1 sub def} def
  45.  
  46. /Colour  0 def %base colour variable
  47. /Parity 0 def        /Swap {/Parity 0.5 Parity sub def} def
  48. /Odd-colour {/Colour Parity def} def
  49. /Even-Colour {/Colour 0.5 Parity sub def} def 
  50. /White {/Colour 1 def} def 
  51. /Comp {Colour 1 ne {1 setgray} {0 setgray} ifelse} def
  52.  
  53. /cm {28.35 mul} def     /Root2 2 sqrt def    /Invr2 0.5 sqrt def
  54. /HeadMatrix matrix        %create matrix for head triangle
  55.      45 matrix rotate matrix concatmatrix
  56.     Invr2 neg Invr2 matrix scale  matrix concatmatrix
  57.     0 10 matrix translate matrix concatmatrix def    
  58.         %cf 0 10 translate Invr2 neg Invr2 scale 45 rotate 
  59.  
  60. /UpheadMatrix HeadMatrix matrix invertmatrix def
  61.         % cf -45 rotate Root2 neg Root2 scale 0 -10 translate
  62.  
  63. /TailMatrix matrix        %create matrix for tail triangle
  64.       -45 matrix rotate matrix concatmatrix
  65.      Invr2 neg Invr2 matrix scale  matrix concatmatrix
  66.     0 10 matrix translate matrix concatmatrix   def 
  67.         %cf {0 10 translate Invr2 neg Invr2 scale -45 rotate} 
  68.  
  69. /UptailMatrix TailMatrix matrix invertmatrix def
  70.             % cf 45 rotate Root2 neg Root2 scale 0 -10 translate
  71.  
  72. /Op1 matrix          %matrix for duple opposite
  73.     0 -10 matrix translate matrix concatmatrix 
  74.     180 matrix rotate matrix concatmatrix
  75.     0 10 matrix translate matrix concatmatrix def
  76.         
  77. /Downhead {HeadMatrix concat} def          %apply to CTM
  78. /Uphead  {UpheadMatrix concat} def        %apply to CTM
  79. /Downtail {TailMatrix concat}  def          %apply to CTM
  80. /Uptail {UptailMatrix concat} def        %apply to CTM
  81. /Op {Op1 concat} def                 %apply to CTM
  82.  
  83. /DwnR {HeadMatrix transform} def    %applies Head matrix to point
  84. /UpR {UpheadMatrix transform} def    %applies UpHead matrix to point
  85. /DwnL {TailMatrix transform} def    %applies Tail matrix to point
  86. /UpL {UptailMatrix transform} def    %applies UpTail matrix to point
  87. /Opp {Op1 transform} def        %applies opposite matrix to point
  88.  
  89. /Qflip {exch neg exch} def         %Flip by X, X/Y point 180
  90. /Qrot90 {exch neg} def             %rotate X/Y point   -90
  91. /Qrotm90 {neg exch } def         %rotate X/Y point 90
  92. /Qxtran {3 -1 roll add exch} def      %adds top to 3rd, X
  93.  
  94. /A {10 10} def         /A1 {9 8} def          /A2 {7.5 6.2} def
  95. /Ah {A -1 Qxtran -0.5 add } def
  96. /B {6 5.6} def         /B1 {4.8 5} def        /B2 {2.2 4.5} def
  97. /C {0 5} def          /C1 {-1.1 5.3} def    /C2 {-4.2 6} def
  98. /D {B Qrotm90} def      /D1 {A1 Qrotm90} def    /D2 {A2 Qrotm90} def  
  99. /E {A Qrotm90} def    /E1 {A1 DwnL} def     /E2 {A2 DwnL} def
  100. /Eh {Ah Qflip} def
  101. /F {B DwnL} def        /F1 {F 2 Qxtran 2 sub} def     /F2 {-2 7} def
  102. /G {0 7.6} def         /G1 {2 8.2} def        /G2 {3.2 9.5 } def
  103. /Gt {G UpL} def
  104. /H {5.1 10} def        /H1 {6.5 10.5} def    /H2 {8 10.5} def
  105.             /I1 {0 4} def        /I2  {0 2} def 
  106. /J {0 0} def        /J1 {3 0} def        /J2 {3 0} def
  107. /K {C Qrot90} def
  108. /L {C DwnR} def        /L1 {C1 DwnR }def    /L2 {4.7 11} def
  109. /N {0 10.7} def        /N1 {I1 DwnR} def    /N2 {I2 DwnR} def
  110. /Nt {N UpL} def 
  111. /P {L Qflip} def
  112.             /Q1 {4.1 12.4} def    /Q2 {2 13.1} def
  113.  
  114. /a {A1 A2 B} def    /b {B1 B2 C} def 
  115. /c {C1 C2 D} def       
  116. /d {D2 D1 E} def    /e {E1 E2 F} def    
  117. /f {F1 F2 G} def    /fr {F2 UpL F1 UpL F UpL} def
  118. /g {G1 G2 H} def
  119. /h {H1 H2 A} def    /hr {H2 H1 H} def    
  120. /i {I1 I2 J } def    /j {J1 J2 K} def    
  121. /k {C1 Qrot90 C2 Qrot90 B} def    % c with 90 rotate about O
  122. /l {L2 L1 L} def      /lr {L1 L2 H} def    %l reversed
  123. /n {N1 N2 N } def    /ns {I1 I2 N UpR} def     /nm (J M P) def
  124. /o {G} def        /ot {Gt} def         % straight line
  125. /p {I2  Qrot90 I1 Qrot90 C Qrot90} def %ie of tailfish 
  126. /pr {I1 I2 Nt } def     
  127. /q {Q1 Q2 G Opp} def    /s {Comp nm Pup} def    
  128.  
  129. /Fr1 {            %Fish righthand (convex side)
  130.     A  moveto  a  curveto b curveto  c curveto  d curveto 
  131.       } def 
  132.  
  133. /Fr2 {          %Fish righthand for 45 deg angle
  134.     A  moveto  a  curveto b curveto 
  135.     Uphead         %always used in head half
  136.         lr curveto   h curveto    
  137.     Downhead
  138.       } def
  139.  
  140. /Fl1 {             %Fish lefthand (concave side)
  141.     e curveto f curveto   g curveto  h curveto   
  142.       } def
  143.  
  144. /Fl2 {             %Fish lefthand for duple  
  145.     Op         %using opposite fish points
  146.         hr curveto  q curveto 
  147.     Op          %cancelling Op 
  148.     g curveto  h curveto    
  149.       } def
  150.     
  151. /Fc1 {          %Fishcentre inside
  152.     Ah moveto   C C -0.6 Qxtran Eh curveto
  153.       } def
  154.  
  155. /Fc2 {             %Fish centre outside and blunt ends
  156.     Eh -0.05 add lineto  
  157.     C -0.25 add -0.6 Qxtran C -0.25 add Ah -0.05 add curveto
  158.     Ah lineto
  159.       } def
  160.  
  161. /Tailrib1 {newpath -6 9 moveto -5 8 -4 7.3 -2.4 6.9 curveto
  162.     stroke} def
  163. /Tailrib2 {newpath -5.5 6.7 moveto -4.5 6.3  -3.5 6.2 -2.3 6 curveto
  164.     stroke} def
  165. /Tailrib3 {newpath -2.2 7.1 moveto -2.4 6.7  -2.4 6.2 -2.2 5.8 curveto
  166.     stroke} def
  167. /Tailribs  {Tailrib1 Tailrib2 Tailrib3} def
  168.  
  169. /EyeshapeL {newpath -0.4 0.8 moveto 0.7 1.3 1.5 1.2 2.5 0.8 curveto
  170.     1.9  0   1.1 -0.4   0.1 -0.9 curveto
  171.     0  -0.2  -0.1 0.3  -0.4 0.8 curveto closepath} def
  172. /EyeL {gsave  5.6 8.9 translate EyeshapeL 
  173.     Colour 1 ne {fill}{stroke} ifelse grestore} def
  174.  
  175. /EyePupL {   gsave 5.8 9 translate  0.4 0.4 scale  EyeshapeL
  176.     fill grestore } def
  177.  
  178. /EyeshapeR { newpath 0  0.8 moveto 1.4 1.6  1.9 1.6  2.6 1.5 curveto
  179.     2.4 0.8  1.6 0  0.1 -0.8 curveto
  180.     0.1 -0.3 0.1 0.3  0 0.8 curveto closepath } def
  181.  
  182. /EyeR {gsave 5.9 6.7 translate EyeshapeR  
  183.     Colour 1 ne {fill}{stroke} ifelse grestore} def
  184.  
  185. /EyePupR {   gsave 6.1 6.7 translate  0.4 0.4 scale  EyeshapeR 
  186.     fill grestore} def
  187.  
  188. /Pupcol {Colour 1 ne  {Colour setgray } if  } def
  189.  
  190. /Pup    {-3 0 moveto show} def
  191.  
  192. /FishMain {    Comp    %compliment colour
  193.     newpath  Fc1 Fc2  closepath  gsave fill grestore    
  194.     Tailribs
  195.     0.01 setlinewidth  EyeR EyeL 
  196.     Pupcol EyePupR EyePupL } def
  197.  
  198. /Fish { Colour setgray newpath     Fr1 Fl1  closepath  gsave fill grestore
  199.     FishMain } def
  200.  
  201. /Fishd { Colour setgray newpath  Fr1 Fl2  closepath  gsave fill grestore
  202.     FishMain} def
  203.  
  204. /Fish45r {Colour setgray newpath  Fr2 Fl1  closepath    gsave fill grestore
  205.     FishMain } def
  206.   
  207. /Fish45d { Colour setgray newpath  Fr2 Fl2  closepath   gsave fill grestore
  208.     FishMain} def
  209.  
  210. /Ribl {newpath H moveto l curveto  stroke } def
  211. /Ribk {newpath K moveto k curveto  stroke }def
  212. /Ribf {newpath Gt moveto fr curveto stroke } def
  213. /Ribb {newpath B moveto b curveto  stroke } def
  214. /Ribg {newpath G moveto g curveto stroke} def
  215.  
  216. /Wingribs %stack SideRib WingRib Translate-offset Translate-inc Y-Scale-inc
  217.     {4 copy 4 copy         %copy parameters given for 3 ribs
  218.     Comp    0.15 setlinewidth 
  219.     0 1 2 {gsave                  %stack --Wr To Ti Sy Loopv
  220.         dup dup    0.25 mul 0.75 exch sub     %stack ----Sy Lv Lv Sx 
  221.         exch 4 -1 roll mul 0.95 exch sub %stack ---To Ti Lv Sx Sy
  222.             scale              %stack --To Ti Lv
  223.         mul add 0 exch  translate     %stack --Wr 
  224.       cvx exec              %execute WingRibxx
  225.         grestore } for         %stack Sr
  226.       cvx exec } def          %execute Sideribxx
  227.  
  228. /QuadWing { Colour setgray newpath        %wing for quad
  229.     C moveto  i curveto  j curveto   k curveto  b curveto 
  230.     closepath  fill 
  231.     /Ribb /Ribk 0.5  0  0 Wingribs
  232.        } def
  233.  
  234. /TriWing1    { Colour setgray newpath     %wing on Hypoteneuse for triple
  235.     G moveto  g curveto  l curveto   n curveto  o lineto 
  236.     closepath  fill 
  237.     /Ribg /Ribl -0.5 0 0.04 Wingribs  } def
  238.  
  239. /TriWing2 { Colour setgray newpath         %wing on head side for triple
  240.     C moveto  ns curveto  p curveto  k curveto  b curveto
  241.     closepath  fill 
  242.     /Ribb /Ribk 0.5 0.1 0 Wingribs     } def
  243.  
  244. /TriWing3 { Colour setgray  newpath        %wing on tail side for triple
  245.     C moveto  pr curveto   ot lineto   fr curveto  b curveto 
  246.     closepath  fill 
  247.     /Ribb /Ribf 0.8 0.6 0.03 Wingribs    }def
  248.  
  249. /DupleWing {  Colour setgray newpath        %wing for duple
  250.     G moveto  g curveto  q curveto o lineto
  251.     closepath  fill 
  252.     /Ribg /Ribl -0.5 0 0.04 Wingribs }def
  253.  
  254. /Wings0 {QuadWing TriWing1} def 
  255. /Wings1 {TriWing2 TriWing1} def
  256. /Wings2 {TriWing3 TriWing1} def
  257. /Wings3 {TriWing2 DupleWing} def
  258. /Wings4 {TriWing3 DupleWing} def
  259. /Wings5 {QuadWing DupleWing} def    
  260.  
  261. /Headpair {Downhead
  262.            Odd-colour Wings1 Fish45r     %fish Hh
  263.           Down  Sextet   Up      % recurse to smaller level     
  264.       -90 rotate                %Uphead Downtail
  265.          Even-Colour   Wings4 Fishd   
  266.        Uptail             %fish Ht
  267.     } def
  268. /Tailpair {Downhead 
  269.         White Wings3 Fish45d    %fish Th
  270.        -90 rotate            %Uphead    Downtail
  271.            Odd-colour Wings2 Fish   %fish Tt
  272.           Down  Sextet Up     
  273.        Uptail } def
  274.  
  275. /Sextet {level maxlevel le {
  276.     Downhead 
  277.         White  Wings1 Fish45r        %fish H
  278.             Headpair
  279.         -90 rotate                %Uphead+downtail
  280.         Even-Colour  Wings2 Fish          %fish  T
  281.          Tailpair  
  282.         Uptail
  283.      }if} def
  284.  
  285. /RCorner {level maxlevel le {
  286. 20 0 translate 
  287.    Downtail
  288.     Downhead 
  289.          White  Wings5 Fish45d        %fish Th with S wing
  290.     -90 rotate                %Uphead Downtail 
  291.           Odd-colour  Wings0 Fish          %fish Tt
  292.         Down  Sextet RCorner Up
  293.     Uptail 
  294.    Uptail 
  295. -20 0 translate
  296.     }if } def 
  297.  
  298. /LCorner {level maxlevel le {
  299. -20 0 translate 
  300.    Downhead 
  301.     Downtail 
  302.         Even-Colour Wings5 Fishd       %fish Ht with S wing
  303.     90 rotate            %Uptail Downhead
  304.          Odd-colour Wings0 Fish     
  305.         Down  Sextet  LCorner Up
  306.     Uphead
  307.    Uphead
  308. 20 0 translate
  309.     }if } def 
  310.  
  311. /Centre {Odd-colour  Wings0 Fish} def
  312.  
  313. gsave
  314.   10 cm 15 cm translate   
  315.   0.3 cm 0.3 cm scale 0.05 setlinewidth  
  316.   1 setflat 1 setlinecap
  317. %%  133 45 {0.5 mul add} setscreen
  318.   60 40 {dup mul exch dup mul add 1.0 exch sub} setscreen
  319. 4 {Centre Sextet RCorner LCorner Swap -90 rotate} repeat s
  320. grestore
  321. showpage
  322.  
  323. %%Trailer
  324. %%Pages: 1 
  325. %%DocumentFonts: Helvetica-Bold
  326. -- 
  327. Ross Smith  rsmith@well.sf.ca.us   {apple,pacbell,hplabs,ucbvax}!well!rsmith
  328.  
  329.  
  330.