% (c) 2004 Andrzej Wasowski, IT Univeristy % % A fractal star drawn recursively, very much like in: % M. Weiss. Data Structures & Problem Solving Using Java. % Addison-Wesley 1998, p. 188 % % The program is written in an obscure language of METAPOST (a % language for programming vector graphics for Latex documents, very % similar in principle to METAFONT, which is the language used by TeX % to describe fonts). % % To see the result call METAPOST: % % mpost star.mp % % this will produce a file named "star.0" which is a viewable % postscript. Either print it, or view in gv: % % gv star.0 % % This postscript can be directly included into a TeX document. % % METAPOST (mpost, sometimes called mp) is usually available on % machines with LaTeX installations, in particular on ssh.itu.dk % left, right should be given in centimeters (or any other measure) % def drawFractal( expr xCenter, yCenter, boundingDim ) = begingroup save side, left, top, right, bottom; numeric side, left, top, right, bottom; side := boundingDim / 2; if side < .5mm: % change values to achieve finer granularity else: % compute corners left := xCenter - side / 2; top := yCenter - side / 2; right := xCenter + side / 2; bottom:= yCenter + side / 2; % recursively draw four quadrants drawFractal (left, top, boundingDim / 2); drawFractal (left, bottom, boundingDim / 2); drawFractal (right, top, boundingDim / 2); drawFractal (right, bottom, boundingDim / 2); % draw Central square, overlapping quadrants fill (left,top)--(right,top)--(right,bottom)--(left,bottom)--cycle withcolor black; fi endgroup; enddef; beginfig(0) drawFractal(11cm,18cm,10cm); endfig; end