Dragon.p
Below is the text of a Pascal program
dragon.p
which writes a postscript file
dragon.ps
for an approximation to the dragon's tooth fractal.
{ Draw dragon's tooth. Output is raw postscript file. }
program DragonTooth;
const pi = 3.14159265;
var
outfile: text;
L: integer;
procedure tooth (x, y, r, theta: real; L: integer);
begin
if L = 0 then
begin
writeln(outfile, x : 1 : 6, ' ', y : 1 : 6, ' moveto');
writeln(outfile, r * cos(theta) : 1 : 6, ' ', r * sin(theta) : 1 : 6, ' rlineto');
writeln(outfile, 'stroke');
writeln(outfile);
end
else
begin
r := r / 3;
L := L - 1;
tooth(x, y, r, theta, L);
x := x + r * cos(theta);
y := y + r * sin(theta);
theta := theta + pi / 3;
tooth(x, y, r, theta, L);
x := x + r * cos(theta);
y := y + r * sin(theta);
theta := theta - 2 * pi / 3;
tooth(x, y, r, theta, L);
x := x + r * cos(theta);
y := y + r * sin(theta);
theta := theta + pi / 3;
tooth(x, y, r, theta, L);
end;
end;
begin
write(' Enter level of recursion > ');
readln(L);
writeln(' Postscript output will be in dragon.ps');
rewrite(outfile, 'dragon.ps');
writeln(outfile, '% Dragons tooth ');
writeln(outfile);
writeln(outfile, '/inch {72 mul} def');
writeln(outfile, '/k 5 inch def');
writeln(outfile, '4.25 inch k 2 div sub 5.5 inch k 4 div sub translate');
writeln(outfile, 'k k scale');
writeln(outfile, '0.1 k div setlinewidth');
writeln(outfile);
tooth(0, 0, 1, 0, L);
writeln(outfile);
writeln(outfile, 'showpage');
close(outfile);
end.
% Dragons tooth
/inch {72 mul} def
/k 5 inch def
4.25 inch k 2 div sub 5.5 inch k 4 div sub translate
k k scale
0.1 k div setlinewidth
0.000000 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.037037 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.055556 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.074074 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.111111 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.129630 0.032075 moveto
-0.018519 0.032075 rlineto
stroke
0.111111 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.148148 0.064150 moveto
0.018519 0.032075 rlineto
stroke
0.166667 0.096225 moveto
0.018519 -0.032075 rlineto
stroke
0.185185 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.222222 0.064150 moveto
-0.018519 -0.032075 rlineto
stroke
0.203704 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.222222 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.259259 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.277778 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.296296 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.333333 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.351852 0.032075 moveto
-0.018519 0.032075 rlineto
stroke
0.333333 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.370370 0.064150 moveto
0.018519 0.032075 rlineto
stroke
0.388889 0.096225 moveto
-0.018519 0.032075 rlineto
stroke
0.370370 0.128300 moveto
-0.037037 0.000000 rlineto
stroke
0.333333 0.128300 moveto
0.018519 0.032075 rlineto
stroke
0.351852 0.160375 moveto
-0.018519 0.032075 rlineto
stroke
0.333333 0.192450 moveto
0.037037 0.000000 rlineto
stroke
0.370370 0.192450 moveto
0.018519 0.032075 rlineto
stroke
0.388889 0.224525 moveto
0.018519 -0.032075 rlineto
stroke
0.407407 0.192450 moveto
0.037037 0.000000 rlineto
stroke
0.444444 0.192450 moveto
0.018519 0.032075 rlineto
stroke
0.462963 0.224525 moveto
-0.018519 0.032075 rlineto
stroke
0.444444 0.256600 moveto
0.037037 0.000000 rlineto
stroke
0.481481 0.256600 moveto
0.018519 0.032075 rlineto
stroke
0.500000 0.288675 moveto
0.018519 -0.032075 rlineto
stroke
0.518519 0.256600 moveto
0.037037 0.000000 rlineto
stroke
0.555556 0.256600 moveto
-0.018519 -0.032075 rlineto
stroke
0.537037 0.224525 moveto
0.018519 -0.032075 rlineto
stroke
0.555556 0.192450 moveto
0.037037 0.000000 rlineto
stroke
0.592593 0.192450 moveto
0.018519 0.032075 rlineto
stroke
0.611111 0.224525 moveto
0.018519 -0.032075 rlineto
stroke
0.629630 0.192450 moveto
0.037037 0.000000 rlineto
stroke
0.666667 0.192450 moveto
-0.018519 -0.032075 rlineto
stroke
0.648148 0.160375 moveto
0.018519 -0.032075 rlineto
stroke
0.666667 0.128300 moveto
-0.037037 -0.000000 rlineto
stroke
0.629630 0.128300 moveto
-0.018519 -0.032075 rlineto
stroke
0.611111 0.096225 moveto
0.018519 -0.032075 rlineto
stroke
0.629630 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.666667 0.064150 moveto
-0.018519 -0.032075 rlineto
stroke
0.648148 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.666667 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.703704 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.722222 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.740741 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.777778 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.796296 0.032075 moveto
-0.018519 0.032075 rlineto
stroke
0.777778 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.814815 0.064150 moveto
0.018519 0.032075 rlineto
stroke
0.833333 0.096225 moveto
0.018519 -0.032075 rlineto
stroke
0.851852 0.064150 moveto
0.037037 0.000000 rlineto
stroke
0.888889 0.064150 moveto
-0.018519 -0.032075 rlineto
stroke
0.870370 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.888889 0.000000 moveto
0.037037 0.000000 rlineto
stroke
0.925926 0.000000 moveto
0.018519 0.032075 rlineto
stroke
0.944444 0.032075 moveto
0.018519 -0.032075 rlineto
stroke
0.962963 0.000000 moveto
0.037037 0.000000 rlineto
stroke
showpage