THE FINAL COUNTDOWN
[ipdf/sam.git] / figures / koch.ps
1 %!PS-Adobe-3.0 EPSF-3.0
2 %%BoundingBox: -40 -40 140 120
3 % Generates a koch snowflake, or crashes your pdf viewer, whichever you prefer.
4
5
6 % Usage:
7 % x1 y1 x2 y2 iterations koch x1 y1 ... x2 y2
8 /koch {
9         20 dict begin
10         /iteration exch def
11         /y2 exch def
12         /x2 exch def
13         /y1 exch def
14         /x1 exch def
15         /dy y2 y1 sub def
16         /dx x2 x1 sub def
17         /dist dx dx mul dy dy mul add sqrt def
18         /nx 0 dy sub dist div def
19         /ny dx dist div def
20
21         /xA dx 3 div x1 add def
22         /yA dy 3 div y1 add def 
23         /xB dist 3 div nx mul dx 2 div add x1 add def
24         /yB dist 3 div ny mul dy 2 div add y1 add def
25         /xC dx 3 div 2 mul x1 add def
26         /yC dy 3 div 2 mul y1 add def 
27         
28         iteration 0 gt
29         {
30                 /next_iteration iteration 1 sub def
31
32                 x1 y1 xA yA next_iteration koch
33                 xA yA xB yB next_iteration koch
34                 xB yB xC yC next_iteration koch
35                 xC yC x2 y2 next_iteration koch
36                 %xB debug
37         }
38         {
39                 x1 y1 lineto x2 y2 lineto
40                 
41         } ifelse
42         end
43 } def
44
45 /debug { moveto 20 string cvs  show} bind def
46 /Coronet findfont 12 scalefont setfont % Fancy font!
47
48 % End prolog
49
50 /iterations 7 def % Define to the desired number of iterations to crash your pdf viewer
51 0 0 1 setrgbcolor
52 0 0 moveto
53 0 0 50 100 iterations koch 
54 50 100 100 0 iterations koch
55 100 0 0 0 iterations koch closepath
56 stroke 
57
58 % Draw some text and the initial triangle faintly
59 0.9 0.9 1 setrgbcolor
60 (Koch's) 38 40 debug
61 (Snowflake) 28 28 debug
62 1E-6 setlinewidth
63 0 0 moveto 50 100 lineto 100 0 lineto 0 0 lineto stroke
64
65
66
67 showpage

UCC git Repository :: git.ucc.asn.au