Mega Code Archive

 
Categories / Delphi / Graphic
 

How to draw an arrow

Title: How to draw an arrow procedure ZeichnePfeil(I: TImage; P1, P2: TPoint); //created by Christof Urbaczek function GetDEG(Winkel: Extended): Extended; Result := (Winkel * 2 * Pi) / 360; end; function GetRAD(Winkel: Extended): Result := (Winkel * 360) / (2 * Pi); end; const s = 10; Beta = 50; Punkte: array [0..2] of TPoint; Alpha, AlphaZ: Extended; begin I.Canvas.Brush.Color := clBlack; I.Canvas.Pen.Style := psSolid; I.Canvas.MoveTo(P1.X, P1.Y); I.Canvas.LineTo(P2.X, P2.Y); Punkte[0].X := P2.X; Punkte[0].Y := P2.Y; Alpha := 0; if P2.X = P1.X then AlphaZ := 0 else AlphaZ := GetRAD(ArcTan((P2.Y - P1.Y) / (P2.X - P1.X))); if (P2.X P1.X) and (P2.Y = P1.Y) then Alpha := 0 else if (P2.X P1.X) and (P2.Y .Y) then Alpha := 0 - AlphaZ else if (P2.X = P1.X) and (P2.Y .Y) then Alpha := 90 else if (P2.X .X) and (P2.Y .Y) then Alpha := 180 - AlphaZ else if (P2.X .X) and (P2.Y = P1.Y) then Alpha := 180 else if (P2.X .X) and (P2.Y P1.Y) then Alpha := 180 - AlphaZ else if (P2.X = P1.X) and (P2.Y P1.Y) then Alpha := 270 else if (P2.X P1.X) and (P2.Y P1.Y) then Alpha := 360 - AlphaZ; //2.Punkt Punkte[1].X := round(P2.X - s * cos(GetDEG(Alpha - Beta div 2))); Punkte[1].Y := round(P2.Y + s * sin(GetDEG(Alpha - Beta div 2))); Punkte[2].X := round(P2.X - s * cos(GetDEG(Alpha + Beta div 2))); Punkte[2].Y := round(P2.Y + s * sin(GetDEG(Alpha + Beta div 2))); I.Canvas.Brush.Color := clBlack; I.Canvas.Polygon(Punkte); end; procedure TForm1.Button1Click(Sender: TObject); begin ZeichnePfeil(Image1, Point(20,20), Point(100,150)); end;