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
|
unit Ugraphisme;
interface
uses Windows,graphics,Extctrls,types,classes,controls,math;
type reel=extended;
type Trpoint=record
x,y:reel;
end;
type Tgraphique=class(Tbitmap)
private
r:Trect;
xo,yo,xmin,ymin,xmax,ymax:reel;
public
constructor Create(w,h:integer;x1,x2,y1,y2:reel);reintroduce;overload;
procedure line(x1,y1,x2,y2:reel);
procedure obturation(cl:Tcolor);
end;
implementation
const M:integer=1000000;
constructor Tgraphique.Create(w,h:integer;x1,x2,y1,y2:reel);
var XFrm:XForm;
begin
inherited create;
width:=w;
height:=h;
//------------------------------
xmin:=x1;
xmax:=x2;
ymin:=y1;
ymax:=y2;
//-------------------------------
xFrm.eM11 :=w/(M*(xmax-xmin));
xFrm.eM22 := -h/(M*(ymax-ymin));
xFrm.eM12 := 0;
xFrm.eM21 := 0;
//--------------------------------
xFrm.eDx :=-w*xmin/(xmax-xmin);
xFrm.eDy :=ymax*h/(ymax-ymin);
//--------------------------------
SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
setworldtransform(canvas.handle,xFrm);
//--------------------------------
with r do begin
left:=round(M*xmin);
top:=-round(M*ymax);
right:=round(M*xmax);
bottom:=-round(M*ymin);
end;
end;
procedure TGraphique.line(x1,y1,x2,y2:reel);
begin
with canvas do
begin
moveto(round(x1*M),round(y1*M));
lineto(round(x2*M),round(y2*M));
end;
end;
procedure Tgraphique.obturation(cl:Tcolor);
begin
with canvas do begin
brush.Color:=cl;
fillrect(r);
end;
end;
end. |
Partager