1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| procedure TMainForm.CalcSin;
var
v, i, imax : integer;
sA, sB, sC : integer; // Signaux générés
AB, BC, CA : Integer; // Compte les différences entre les signaux
clrA, clrB, clrC : TColor;
angle, delta, volume : double;
begin
lblAB.Caption := '0';
lblBC.Caption := '0';
lblCA.Caption := '0';
imax := 255;
delta := 2.0*PI/imax; // On fait "presque" un tour complet
volume:= 0.0;
img.Canvas.Brush.Color:= 0;
img.Canvas.FillRect(0,0,256, 512);
for v := 1 to 10 do begin
volume += 12.7; // 0 (exclus) à 127
lblVol.Caption := Format('%5.1f', [volume]);
AB := 0;
BC := 0;
CA := 0;
angle := 0;
for i := 0 to imax do begin
angle += delta;
sA := round(127 - volume*sin(angle)); // 0 à 254 => une position perdue, f(0) = 127
sB := round(128 - volume*sin(angle)); // 1 à 255 => une position perdue, f(0) = 128
sC := round(127.5 - (volume+0.5)*sin(angle)); // 0 à 255 => gamme complète, f(0) = 128
clrA := $FF0000 or ($0000FF and -Ord(sA = sB)) or ($00FF00 and -Ord(sC = sA));
clrB := $0000FF or ($FF0000 and -Ord(sA = sB)) or ($00FF00 and -Ord(sB = sC));
clrC := $00FF00 or ($FF0000 and -Ord(sC = sA)) or ($0000FF and -Ord(sB = sC));
img.Canvas.Pixels[i, sA << 1] := clrA;
img.Canvas.Pixels[i, sB << 1] := clrB;
img.Canvas.Pixels[i, sC << 1] := clrC;
img.Canvas.Pixels[i, (sA << 1) or 1] := clrA;
img.Canvas.Pixels[i, (sB << 1) or 1] := clrB;
img.Canvas.Pixels[i, (sC << 1) or 1] := clrC;
if sA <> sB then inc(AB);
if sB <> sC then inc(BC);
if sC <> sA then inc(CA);
end;
lblAB.Caption := IntToStr(AB);
lblBC.Caption := IntToStr(BC);
lblCA.Caption := IntToStr(CA);
Application.ProcessMessages;
Sleep(1000);
end;
end; |
Partager