Программирование - это просто
Advertisement
arrow Delphi arrow Delphi arrow (TCanvas, TImage, Polygon)
07.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
(TCanvas, TImage, Polygon) E-mail
megabax   
22.09.2009 .
New Page 2

 (TCanvas, TImage, Polygon)

.

Delphi, TImage, TCanvs   , , , , , DirectX, .

, . , . . , TAxesSystem, :

TAxesSystem=class(TObject)
public
     X, Y:integer;
     RatioX, RatioY:double;
     function GetX(AX:double):integer;
     function GetY(AY:double):integer;
     function GetPoint(AX, AY:Double):TPoint;
end;

, Public, Private Protected . , .

:

function TAxesSystem.GetX(AX:double):integer;
begin
    result:=X+round(AX/RatioX);
end;

function TAxesSystem.GetY(AY:double):integer;
begin
    result:=Y+round(AY/RatioY);
end;

function TAxesSystem.GetPoint(AX, AY:Double):TPoint;
begin
    Result.X:=GetX(AX);
    Result.Y:=GetY(AY);
end;

. GetX GetY . X Y - . :

 ,    ,  TCanvas, TImage, Polygon

, . Y . , . round - . . , 10 .   1:10 (RatioX RatioY 0,1). . X Y.

, , . TImage, Additional*:

   ,  TCanvas, TImage, Polygon

, , TSpinEdit *.

 TCanvas, TImage, Polygon

*:

 ,  TCanvas, TImage, Polygon

edX edY, TSpinEdit seX seY.

OnClick

procedure TfrmGameSample.btnShowClick(Sender: TObject);
var Points:array[1..5] of TPoint; i:integer; Axes:TAxesSystem;
      Trian:array[1..5,1..2] of double;
      Rect:TRect;
begin
      Trian[1,1]:=1;
      Trian[1,2]:=2;

      Trian[2,1]:=5;
      Trian[2,2]:=4;

      Trian[3,1]:=4;
      Trian[3,2]:=2;

      Trian[4,1]:=4;
      Trian[4,2]:=-1;

      Trian[5,1]:=3;
      Trian[5,2]:=-1;

    Axes:=TAxesSystem.Create;

    //
    Axes.X:=seX.Value;
    Axes.Y:=seY.Value;
    Axes.RatioX:=StrToFloat(edRatioX.Text);
    Axes.RatioY:=StrToFloat(edRatioY.Text);

   for i:=1 to 5 do Points[i]:=Axes.GetPoint(Trian[i,1],Trian[i,2]);

   // , FillRect TCanvas, TImage
   Rect.Left:=0;
   Rect.Top:=0;
   Rect.Right:=imImage.Width;
   Rect.Bottom:=imImage.Height;
   imImage.Canvas.FillRect(Rect);

   //
  imImage.Canvas.Polygon(Points);
end;

. ,   TPoint. TAxesSystem, . (TImage),   FillRect TCanvas, TImage, . , (TImage) . , , Polygon TCanvas, TImage.

 ,    ,  TCanvas, TImage, Polygon

, Y , , Y .

" ":

 ,    ,  TCanvas, TImage, Polygon

:

   ,  TCanvas, TImage, Polygon

. OnClick , , :

procedure TfrmGameSample.btnShowClick(Sender: TObject);
var Points:array[1..7] of TPoint; i:integer; Axes:TAxesSystem;
      Rect:TRect;
      Trian:array[1..7,1..2] of double;
begin
      Trian[1,1]:=-1;
      Trian[1,2]:=2;

      Trian[2,1]:=0;
      Trian[2,2]:=4;

      Trian[3,1]:=1;
      Trian[3,2]:=1;

      Trian[4,1]:=6;
      Trian[4,2]:=1;

      Trian[5,1]:=4;
      Trian[5,2]:=-1;

      Trian[6,1]:=2;
      Trian[6,2]:=0.5;

     Trian[7,1]:=0;
     Trian[7,2]:=-3;

     Axes:=TAxesSystem.Create;

     //
     Axes.X:=seX.Value;
     Axes.Y:=seY.Value;
     Axes.RatioX:=StrToFloat(edRatioX.Text);
     Axes.RatioY:=StrToFloat(edRatioY.Text);

     for i:=1 to 7 do Points[i]:=Axes.GetPoint(Trian[i,1],Trian[i,2]);

     //
     Rect.Left:=0;
     Rect.Top:=0;
     Rect.Right:=imImage.Width;
     Rect.Bottom:=imImage.Height;
     imImage.Canvas.FillRect(Rect);

    //
    imImage.Canvas.Polygon(Points);
end;
 

:

 ,    ,  TCanvas, TImage, Polygon

, , .

.


, *,   . 1274 "Delphi", Borland Delphi.. 


( 06.11.2011 . )
 
« .
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .