program batti1;
(* esempio di onde grafiche e suono applicato *)

uses crt,graph;

procedure grafica;
var sc,tp:integer;
    stringa:string;
begin
 sc:=0;
 tp:=0;
 stringa:='c:\tp\bgi';
 initgraph(sc,tp,stringa);
end;

procedure disegna(a1,a2,a3,a,b,c:integer);
var d,x,y,s1,s2,s3,yr,risu:integer;
    rad1,rad2,rad3,sx,sy,sz:real;
    sr1,sr2,sr3,sr4:string;
begin
cleardevice;
 x:=1;
 y:=100;
 yr:=250;
 setcolor(7);
 outtextxy(10,400,'frequenze delle onde da comporre');
 line(1,y,600,y);
 line(1,yr,600,yr);
 for d:=0 to 600 do
 begin
 str(a1,sr1);
 str(a2,sr2);
 str(a3,sr3);
 rad1:=d*3.14/(180/a1);
 rad2:=d*3.14/(180/a2);
 rad3:=d*3.14/(180/a3);
 sx:=sin(rad1);
 sy:=sin(rad2);
 sz:=sin(rad3);
 s1:=trunc(sx*a);
 s2:=trunc(sy*b);
 s3:=trunc(sz*c);
 risu:=s1+s2+s3;
 str(risu,sr4);
 setcolor(3);
 outtextxy(10,350,sr1);
    line(d,y+s1,d,y+s1);
 setcolor(5);
 outtextxy(10,360,sr2);
    line(d,y+s2,d,y+s2);
 outtextxy(10,370,sr3);
 setcolor(6);
    line(d,y+s3,d,y+s3);
 setcolor(7);
 outtextxy(400,10,'risultante');
 outtextxy(500,10,sr4);
    line(d,yr,d,yr+s1+s2+s3);
 sound(y+s1);
 sound(y+s2);
 sound(y+s3);
 delay(2);
 if (risu=0) then delay(1000);
 setcolor(0);
 outtextxy(500,10,sr4);
   end;
nosound;
outtextxy(10,10,'premi return');
readln;
end;

begin
grafica;
(* frequenze ampiezze *)
disegna(1,2,3,60,60,60);
disegna(2,4,6,60,60,60);
disegna(1,2,3,60,60,60);
disegna(20,21,22,60,60,60);
disegna(10,11,12,60,60,60);
disegna(40,41,42,60,60,0);
closegraph;
writeln('premi enter');
readln;
end.

ritorna