X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fsam.git;a=blobdiff_plain;f=figures%2Fkoch.ps;fp=figures%2Fkoch.ps;h=45f88b2847aa72fa29a9ac430403d8b482141f84;hp=0000000000000000000000000000000000000000;hb=4c0361848c4fa9ccc9d4f100385f2d92728ad341;hpb=1e1740165abac91f4f620ef8223a30e37e7124ab diff --git a/figures/koch.ps b/figures/koch.ps new file mode 100644 index 0000000..45f88b2 --- /dev/null +++ b/figures/koch.ps @@ -0,0 +1,66 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%BoundingBox: -40 -40 140 120 +% Generates a koch snowflake, or crashes your pdf viewer, whichever you prefer. + + +% Usage: +% x1 y1 x2 y2 iterations koch x1 y1 ... x2 y2 +/koch { + 20 dict begin + /iteration exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /dy y2 y1 sub def + /dx x2 x1 sub def + /dist dx dx mul dy dy mul add sqrt def + /nx 0 dy sub dist div def + /ny dx dist div def + + /xA dx 3 div x1 add def + /yA dy 3 div y1 add def + /xB dist 3 div nx mul dx 2 div add x1 add def + /yB dist 3 div ny mul dy 2 div add y1 add def + /xC dx 3 div 2 mul x1 add def + /yC dy 3 div 2 mul y1 add def + + iteration 0 gt + { + /next_iteration iteration 1 sub def + + x1 y1 xA yA next_iteration koch + xA yA xB yB next_iteration koch + xB yB xC yC next_iteration koch + xC yC x2 y2 next_iteration koch + %xB debug + } + { + x1 y1 moveto x2 y2 lineto + + } ifelse + end +} def + +/debug { moveto 20 string cvs show} bind def +/Coronet findfont 12 scalefont setfont % Fancy font! + +% End prolog + + +% Draw some text and the initial triangle faintly +0.9 0.9 1 setrgbcolor +(Koch's) 38 40 debug +(Snowflake) 28 28 debug +1E-6 setlinewidth +0 0 moveto 50 100 lineto 100 0 lineto 0 0 lineto stroke + +/iterations 7 def % Define to the desired number of iterations to crash your pdf viewer +0 0 1 setrgbcolor +0 0 moveto +0 0 50 100 iterations koch +50 100 100 0 iterations koch +100 0 0 0 iterations koch closepath +fill + +showpage