program paport;
uses crt, graph;
var
ch :char;
i,j :integer;
grDriver: Integer;
grMode: Integer;
Procedure Threedfern;
const
a:array[0..3, 0..2, 0..3] of integer =
((( 0, 0, 0, 0),( 0, 20, 0, 0),( 0, 0, 0, 0)),
(( 85, 0, 0, 0),( 0, 85, 11, 70),( 0,-10, 85, 0)),
(( 31,-41, 0, 0),( 10, 21, 0, 21),( 0, 0, 30, 0)),
((-29, 40, 0, 0),( 10, 19, 0, 56),( 0, 0, 30, 0)));
var
b:array[0..99] of integer;
k,n,x,y,z,newx,newy:Integer;
begin
x:=0;
y:=0;
z:=0;
randomize;
repeat
for k:=1 to 99 do
begin
b[k]:=random(10);
if b[k]>3 then b[k]:=1;
end;
for k:=1 to 99 do
begin
newx:=(a[b[k],0,0]*x+a[b[k],0,1]*y+a[b[k],0,2]*z) div 100+a[b[k],0,3];
newy:=(a[b[k],1,0]*x+a[b[k],1,1]*y+a[b[k],1,2]*z) div 100+a[b[k],1,3];
z:=(a[b[k],2,0]*x+a[b[k],2,1]*y+a[b[k],2,2]*z) div 100+a[b[k],2,3];
x:=newx;
y:=newy;
putpixel(350-x+z,400-y,green);
end;
until KeyPressed;
end;
BEGIN
grDriver := Detect;
InitGraph(grDriver, grMode,' ');
Threedfern;
ch:=readkey;
CloseGraph;
END.