{---------------------------------------------------------------------------} { Unit Wrel1 Funzioni/procedure di supporto per la grafica in coordinate { relative in Delphi 1.0 - By Claudio Fin (C) 1997 {---------------------------------------------------------------------------} unit Wrel1; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TFinestraFunzioni=object xmin,xmax,ymin,ymax:real; { Valori sugli assi } xsegm,ysegm:real; paper,ink:TColor; { Colori fondo e inchiostro } Foglio:TImage; procedure DefiWnd(a:TImage; const xxmin,yymin,xxmax,yymax:real); procedure Cls; procedure SetInk(a:Tcolor); procedure SetPaper(a:Tcolor); procedure Plotta(const xx,yy:real); procedure Linea(const xx1,yy1,xx2,yy2:real); procedure Cerchio(const xx,yy,Raggio:real); procedure Testo(const s:string; const xx1,yy1:real); end; implementation {--------------------------------------------------------------------------} procedure TFinestraFunzioni.Testo(const s:string; const xx1,yy1:real); var xq,yq:integer; begin xq:=trunc( ( xx1 - xMIN ) / xSEGM ); yq:=foglio.height-1-trunc( ( yy1 - yMIN ) / ySEGM ); Foglio.canvas.textout(xq,yq,s); end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.Cerchio(const xx,yy,Raggio:real); var lun,xq,yq:integer; begin xq:=trunc( ( xx - xMIN ) / xSEGM ); yq:=foglio.height-1-trunc( ( yy - yMIN ) / ySEGM ); lun:=1+trunc(raggio/xsegm); { Foglio.Canvas.Brush.Style:=BsClear;} Foglio.Canvas.Brush.Color:=paper; Foglio.Canvas.Pen.Color:=ink; Foglio.Canvas.Ellipse(xq-lun,yq+lun,xq+lun,yq-lun); end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.Linea(const xx1,yy1,xx2,yy2:real); var xx1q,yy1q,xx2q,yy2q:integer; begin xx1q:=trunc( ( xx1 - xMIN ) / xSEGM ); xx2q:=trunc( ( xx2 - xMIN ) / xSEGM ); yy1q:=foglio.height-1-trunc( ( yy1 - yMIN ) / ySEGM ); yy2q:=foglio.height-1-trunc( ( yy2 - yMIN ) / ySEGM ); foglio.canvas.moveto(xx1q,yy1q); foglio.canvas.pen.color:=ink; foglio.canvas.lineto(xx2q,yy2q); foglio.canvas.pixels[xx2q,yy2q]:=ink; end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.Plotta(const xx,yy:real); var xq,yq:integer; begin xq:=trunc( ( xx - xMIN ) / xSEGM ); yq:=foglio.height-1-trunc( ( yy - yMIN ) / ySEGM ); foglio.canvas.pixels[xq,yq]:=ink; end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.DefiWnd(a:TImage; const xxmin,yymin,xxmax,yymax:real); begin Foglio:=a; xmin:=xxmin; xmax:=xxmax; ymin:=yymin; ymax:=yymax; xsegm:= ( xMAX - xMIN ) / ( Foglio.Width - 1 ); ysegm:= ( yMAX - yMIN ) / ( Foglio.Height - 1 ); ink:=ClWhite; paper:=ClBlack; Foglio.canvas.font.name:='fixedsys'; Foglio.canvas.font.color:=clwhite; end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.Cls; begin Foglio.Canvas.Pen.Color:=paper; Foglio.Canvas.Brush.Color:=paper; Foglio.Canvas.Brush.Style:=BsSolid; Foglio.Canvas.Rectangle(0,0,Foglio.width,Foglio.Height); Foglio.Canvas.Pen.Color:=Ink; end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.SetInk(a:Tcolor); begin ink:=a; end; {--------------------------------------------------------------------------} procedure TFinestraFunzioni.SetPaper(a:Tcolor); begin paper:=a; end; {--------------------------------------------------------------------------} end.