program creere_valuri;
uses crt,graph;
const nx=25;
      ny=25;
      a=-12;
      b=13;
      c=-12;
      d=13;
      alfa=165;
      beta=-135;
      gama=135;
var gd,gm,dy:integer;
    i,j,tt:byte;
    c1,c2,c3,s1,s2,s3,x,y,z,ux,uy,t:real;
    xmin,xmax,ymin,ymax,al,be,ga:real;
    xx,yy:array[1..nx,1..ny]of real;
function f(x,y:real):real;
begin
f:=sin(t*sqrt(x*x+y*y));
end;
function radiani(u:integer):real;
begin
radiani:=u/180*pi;
end;
procedure init_graph;
begin
gd:=detect;
initgraph(gd,gm,'d:\limbaje\tp7\bgi');
if graphresult<>grok then
  begin
    write('Nu e bun† calea la fisierul egavga.bgi');
    halt(1);
  end;
end;
procedure anim(tt:byte);
begin
al:=radiani(alfa);be:=radiani(beta);ga:=radiani(gama);
c1:=cos(al);s1:=sin(al);
c2:=cos(be);s2:=sin(be);
c3:=cos(ga);s3:=sin(ga);
ux:=abs(b-a)/(nx-1);uy:=abs(d-c)/(ny-1);
x:=a;y:=c;z:=f(x,y);
xx[1,1]:=x*c1+y*c2+z*c3;
yy[1,1]:=x*s1+y*s2+z*s3;
xmin:=xx[1,1];xmax:=xmin;
ymin:=yy[1,1];ymax:=ymin;
for i:=1 to nx do
  begin
    y:=c;
    for j:=1 to ny do
      begin
        z:=f(x,y);
        xx[i,j]:=x*c1+y*c2+z*c3;
        yy[i,j]:=x*s1+y*s2+z*s3;
        if xmin>xx[i,j] then xmin:=xx[i,j]
                        else if xmax<xx[i,j] then xmax:=xx[i,j];
        if ymin>yy[i,j] then ymin:=yy[i,j]
                        else if ymax<yy[i,j] then ymax:=yy[i,j];
        y:=y+uy;
      end;
      x:=x+ux;
    end;
setcolor(tt);
ux:=(xmax-xmin)/(getmaxx-200);
uy:=(ymax-ymin)/(getmaxy-200);
dy:=getmaxy-100;
for i:=1 to nx do
  begin
    moveto(round((xx[i,1]-xmin)/ux),dy-round((yy[i,1]-ymin)/uy));
    for j:=2 to ny do
      lineto(round((xx[i,j]-xmin)/ux),dy-round((yy[i,j]-ymin)/uy));
  end;
for j:=1 to ny do
  begin
    moveto(round((xx[1,j]-xmin)/ux),dy-round((yy[1,j]-ymin)/uy));
    for i:=1 to nx do
      lineto(round((xx[i,j]-xmin)/ux),dy-round((yy[i,j]-ymin)/uy));
  end;
end;
begin
init_graph;
t:=0;
repeat
anim(12);
anim(0);
t:=t+1/100;
until keypressed;
closegraph;
end.