if the outer polygon has its vertices in clockwise order, then the inner polygon must have the points in counter-clockwise order.Ĭonst P : array of of TPoint = ( // outer polygon: a rectangle ( X : 10 Y : 10 ), // <- first point of the rectangle ( X : 190 Y : 10 ), ( X : 190 Y : 190 ), // (clockwise orientation) ( X : 10 Y : 190 ), ( X : 10 Y : 10 ), // <- last point of the rectangle = first point // inner polygon: a triangle ( X : 20 Y : 20 ), // <- first point of the triangle ( X : 40 Y : 180 ), // ( counter-clockwise orientation) ( X : 60 Y : 20 ), ( X : 20 Y : 20 ) // <- last point of the triangle = first point ) procedure TForm1. Make sure that both polygons have opposite orientations, i.e.The order of the inner and outer polygon points in the array does not matter.last point = first point), and that both first and last polygon points are immediately adjacent in the array. You must prepare the array of polygon vertices such that each polygon is closed (i.e.However, you need to consider several important points: Basically the Polygon() method of the LCL canvas is ready for this task. Suppose you want to draw the shape of a country with a large lake inside from both of which you have some boundary points. Polygon ( P2, true ) end Polygon with a hole FormPaint ( Sender : TObject ) var P : Array of TPoint P1, P2 : Array of TPoint i : Integer phi : Double begin for i := 0 to 4 do begin phi := 2.0 * pi / 5 * i + pi * 0.5 P. #Draw triangle free pascal code#The following code example compares both cases: When Winding is False an area is filled by the "even-odd rule" ( ), otherwise by the "non-zero winding rule" ( ). However, owing to the overlapping, different effects can be obtained which depend on the optional Winding parameter of the Polygon() method. This is a self-overlapping polygon and results in a star-shape. Here is a modification of the polygon example: Let's rearrange the polygon points so that the first point is connected to the 3rd initial point, the 3rd point is connected to the 5th point, the 5th point to the 2nd point and the 2nd point to to 4th point. Polygon ( P ) end Self-overlapping polygons Y := round ( 100 * sin ( phi ) + 110 ) end Canvas. FormPaint ( Sender : TObject ) var P : Array of TPoint i : Integer phi : Double begin for i := 0 to 4 do begin phi := 2.0 * pi / 5 * i + pi * 0.5 P. the last array point does not necessarily need to coincide with the first point (although there are cases where this is required - see below). The polygon is closed automatically, i.e. The polygon is defined by an array of points ( TPoint) which are connected by straight lines drawn with the current Pen, and the inner area is filled by the current Brush. Free end end Drawing a polygon Simple polygonĪ polygon is drawn by the Polygon method of the canvas. LoadFromIntfImage ( IntfImg ) // paint Canvas. Colors := colTransparent end end // create bitmap Img. GetTextSize ( TheText, w, h ) if ( w FontColor then IntfImg. Procedure PaintAliased ( Canvas : TCanvas x, y : integer const TheText : string ) var w, h, dx, dy : Integer IntfImg : TLazIntfImage Img : TBitmap col : TFPColor FontColor, c : TColor begin w := 0 h := 0 Canvas. The fill color is determined by the color of the canvas's Brush, and the border color is given by the color of the canvas's Pen: You can pass rectangle's edge coordinates to the method either as four separate x/y values, or as a single TRect record. The TCanvas method for painting a rectangle is named very logically: Rectangle(). Never paint in an OnClick handler, because this painting is not persistent and will be erased whenever the operating system requests a repaint. For this purpose we must add code to the OnPaint event of the form. Suppose we want to draw a red rectangle with a 5-pixel-thick blue border in the center of the form, and the the rectangle should be half the size of the form. #Draw triangle free pascal how to#Let's use TForm as an example to demonstrate how to paint on a canvas. Such controls include TForm, TPanel and TPaintBox. Many controls expose their canvas as a public Canvas property (or via an OnPaint event).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |