HomeMailUpPreviousNextHelp it en

Fractals and PostScript

Somebody says that PostScript files are always too long. The following GIF picture is 17087 bytes long

while the PostScript source code is the following:
%!PS-Adobe-2.0 EPSF-2.0
%%Title: Curva di Koch - by Emanuele Paolini
%%BoundingBox: 0 50 550 660
%%Pages: 1
%%EndComments
%%EndProlog

%%Page: 1 1
/koch {
dup 1 ge {
1 sub gsave
1 3 div dup scale dup koch
1 0 translate 60 rotate dup koch
1 0 translate -120 rotate dup koch
1 0 translate 60 rotate dup koch
grestore} {newpath 0 0 moveto 1 0 lineto stroke}
ifelse pop
} def

20 500 translate
500 500 scale
0.1 setlinewidth

%numero di iterazioni:
8            

dup koch
1 0 translate -120 rotate dup koch
1 0 translate -120 rotate dup koch
showpage

%%Trailer

The whole file is 559 bytes long, comments included. If you have a preview program for PostScript or a PostScript printer, you can try to feed it with the previous PostScript code to see the result: koch.ps.

Notice that PostScript pictures are vectorial, so the printing resolution is only bounded by the resolution of the printer (or the monitor if you use a preview). As a matter of fact, the previous picture is the 8th iteration of the "snow-flock" fractal, and it contains exactly 196608 small segments, each 0.003 cm long.

Notice moreover that the number of iteration can be modified at will simply modifying a number in the source code. PostScript, indeed, is a complete programming language (in reverse polish notation). All the computations needed to draw the fractal, are accomplished by the printer itself.

Other nice fractals written in PostScript:

This is a non periodic tiling: penrose.ps (diby Maurizio Paolini).
HomeMailUpPreviousNextHelp it en
Last updated: dom lug 12 2009