Смекни!
smekni.com

Моделирование схемы Жизнь (стр. 4 из 4)

{} Randomize;

{} for i:=1 to 50 do

{} for j:=1 to 30 do

{} if Random(2)=0 then A[i,j]:=True;

{}

End;

Procedure Draw;

{}

{} var

{} i,j:integer;

{}

Begin

{}

{} Rectangle(0,0,639,349);

{} for i:=0 to 51 do

{} for j:=0 to 31 do

{} begin

{} {}

{} {} if A[i,j] then SetFillStyle(1,10)

{} {} else SetFillStyle(9,1);

{} {} Bar(55+10*i,10+8*j,65+10*i,18+8*j);

{} {} Rectangle(55+10*i,10+8*j,65+10*i,18+8*j);

{} end;

{}

End;

Procedure Copy;

{}

{} var

{} i,j:integer;

{}

Begin

{}

{} for i:=1 to 50 do

{} for j:=1 to 30 do

{} A[i,j]:=B[i,j];

{}

End;

Procedure Print;

Begin

{}

{} Str(step:3,s);

{} stri:='Шаг # '+s;

{} Str(live:3,s);

{} stri:=stri+' Клеток '+s;

{} outtextxy(55,300,stri);

{} Str(born:3,s);

{} stri:='Появилось '+s;

{} Str(dead:3,s);

{} stri:=stri+' Погибло '+s;

{} outtextxy(55,315,stri);

{}

{}

End;

Procedure Count;

{}

{} var

{} i,j:integer;

{}

Begin

{}

{} live:=0;

{} for i:=1 to 50 do

{} for j:=1 to 30 do

{} if A[i,j] then live :=live+1;

{}

End;

BEGIN

Setup;

i:=9;

j:=1;

InitGraph(i,j,'c:\dos');

SetColor(9);

While Change do

begin

{} step:=step+1;

{} FlipVP(VP);

{} Draw;

{} Count;

{} Print;

{} Copy;

{} Delay(22);

{} if KeyPressed then

{} if ReadKey<>''then

{} goto l;

end;

l:

ReadKey;

CloseGraph;

ClrScr;

END.