今天重翻潘金贵的《分形艺术程序设计》,在第230页见到IFS分形山的一段PASCAl小程序和配图,感到非常惊讶,原来大名鼎鼎的PASCAl语言处理起4重仿射变换的迭代来也如此笨拙,而几何画板IFS平台却简单到仅仅填表而已。
{Mount.PAS}
Program IFSMountain;
uses
Graph,Crt;
var
Gd,Gm,ErrorCode : integer;
x,y: real;
k,MaxY:integer;
i:longint;
d: array[1..4,1..6] of real;
begin
Gd:= Detect;
InitGraph(Gd,Gm,'d:\pascal');
ErrorCode := GraphResult;
if ErrorCode <> grOk then exit;
MaxY := GetMaxY;
d[1,1]:=0.5; d[1,2]:=0; d[1,3]:=0;
d[1,4]:=0.5; d[1,5]:=0;d[1,6]:=0;
d[2,1]:=0.5; d[2,2]:=0; d[2,3]:=0;
d[2,4]:=0.5; d[2,5]:=2; d[2,6]:=0;
d[3,1]:=-0.4; d[3,2]:=0; d[3,3]:=1;
d[3,4]:=0.4; d[3,5]:=0; d[3,6]:=1;
d[4,1]:=-0.5; d[4,2]:=0; d[4,3]:=0;
d[4,4]:=0.5; d[4,5]:=2; d[4,6]:=1;
randomize;
x := 0; y := 0;
repeat
i:=i+1;
k := random(4) + 1;
x := d[k,1]*x + d[k,2]*y + d[k,5];
y := d[k,3]*x + d[k,4]*y + d[k,6];
if i > 10 then
putpixel(round(MaxY*x/2),MaxY-round(MaxY*y/2),15)
until keypressed;
closegraph;
end.
|