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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
reel=extended;
TReelpoint=record
x,y:reel;
end;
Tgraphique=class(Tbitmap)
private
xo,yo,xmin,ymin,xmax,ymax,Gx,Gy,taillex,tailley:reel;
public
constructor Create(w,h:integer;x1,x2,y1,y2:reel);reintroduce;overload;
procedure tracerepere(penw:integer;coulpen,clfond:Tcolor);
procedure tracecourbe(trajectoire:array of TReelpoint);
Function ptinfo(x,y:reel):Tpoint;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Déclarations privées }
courbe: array of TReelpoint;
graphique:TGraphique;
public
{ Déclarations publiques }
end;
function pt(x,y:reel):TReelpoint;
var
Form1: TForm1;
implementation
{$R *.dfm}
function pt(x,y:reel):TReelpoint;
begin
result.x:=x;
result.y:=y;
end;
constructor Tgraphique.Create(w,h:integer;x1,x2,y1,y2:reel);
begin
inherited create;
width:=w;
height:=h;
xmin:=x1;
xmax:=x2;
ymin:=y1;
ymax:=y2;
taillex:=xmax-xmin;
tailley:=ymax-ymin;
Gx:=width/taillex;
Gy:=height/tailley;
xo:=-xmin*Gx;
yo:=ymax*Gy;
end;
procedure TGraphique.tracecourbe(trajectoire:array of TReelpoint);//tracé de la courbe à partir d'un tableau de points en coods mathématiques
var
traj:array of Tpoint;
i:integer;
begin
setlength(traj,length(trajectoire));
for i:=low(traj) to high(traj) do begin
traj[i]:=ptinfo(trajectoire[i].x,trajectoire[i].y);
end;
canvas.polyline(traj);
end;
Function TGraphique.ptinfo(x,y:reel):Tpoint;
begin
result:=point(round(xo+x*Gx),round(yo-y*Gy));
end;
procedure Tgraphique.tracerepere(penw:integer;coulpen,clfond:Tcolor); //tracé des axes
begin
with canvas do begin
pen.width:=penw;
pen.color:=coulpen;
brush.Color:=clfond;
fillrect(rect(0,0,width,height));
moveto(0,round(yo));
lineto(width,round(yo));
moveto(round(xo),0);
lineto(round(xo),height);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
position:=poscreencenter;
clientwidth:=screen.height div 2;
clientheight:=screen.Height div 2;
setlength(courbe,101);
for i:= -50 to 50 do courbe[i+50]:= pt(i/10,sin(2*pi*i/50)); //TABLEAU DE POINTS EN COORDS MATHEMATIQUES
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
with graphique do
begin
tracerepere(2,0,clwhite);
canvas.pen.width:=1;
canvas.Pen.color:=clred;
tracecourbe(courbe);
end;
canvas.Draw(0,0,graphique);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
graphique:=TGraphique.Create(clientwidth,clientheight,-5,5,-1.2,1.2); //-5 ...+5 EN ABSCISSE et -1.2.......1.2 EN ORDONNEE
invalidate;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
graphique.Free;
end;
end. |
Partager