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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
PaintBox1: TPaintBox;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormResize(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
w,h,t,periode,nT,A:integer;
graphique:TBitmap;
procedure trace;
procedure init;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
position:=poscreencenter;
width:=screen.Width ;
height:=screen.Height div 2;
periode:=1000; // 1 seconde 60puls/min
timer1.Interval:=10; //10 ms
nT:=4;//nb de périodes sur largeur fenêtre ici 4 ou plus selon vouloir
end;
procedure TfORM1.init;
begin
graphique.Canvas.fillrect(paintbox1.clientrect);
graphique.Canvas.moveto(0,h div 2);
end;
procedure Tform1.trace;
begin
if t=0 then init;
if t>nT*periode then begin
init;
t:=0;
end;
// 4 périodes pour la largeur de la fenêtre =>nT=4
graphique.Canvas.lineto(round(w*t/(nT*periode)),round(h div 2+A*sin(2*pi*t/periode)));
//------------------------------------------------
caption:='t='+floattostr(t/1000)+'s';
paintbox1.Canvas.Draw(0,0,graphique);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
t:=t+timer1.interval;
trace;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
with graphique.canvas do begin
pen.Color:=clred;
pen.Width:=3;
brush.Color:=clblack;
end;
trace;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
w:=form1.ClientWidth;
h:=form1.ClientHeight;
A:=-h div 4;
with paintbox1 do begin
top:=0;
left:=0;
width:=w;
height:=h;
end;
graphique:=tbitmap.Create;
with graphique do begin
width:=w;
height:=h;
end;
t:=0;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
graphique.Free;
end;
end. |
Partager