portxy.blogg.se

Draw triangle free pascal
Draw triangle free pascal










  1. #DRAW TRIANGLE FREE PASCAL HOW TO#
  2. #DRAW TRIANGLE FREE PASCAL CODE#

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 ) // true -> Non-zero winding rule end Polygon with a hole Polygon ( P1, false ) // false -> Even-odd rule Canvas. 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. Ellipse ( R ) end Drawing a polygon Simple polygonĪ polygon is drawn by the Polygon method of the canvas.

draw triangle free pascal draw triangle free pascal

if Width > Height then radius := round ( Height * 0.45 ) else radius := round ( Width * 0.45 ) // The circle then will be enclosed by the rectangle between center.X +/- radius // and center.Y +/- radius R := Rect ( center. The radius, then, is half of this value. Y := Height div 2 // The diameter should be 90% of the width or the height, whichever is smaller. Style := psSolid // We want the circle to be centered in the form center. Style := bsSolid // Set the border color Canvas. FormPaint ( Sender : TObject ) var radius : Integer // Radius of the circle center : TPoint // Center point of the circle R : TRect // Rectangle enclosing the circle begin // Set the fill color Canvas. Knowing that a circle is a special case of an ellipse with equal half-axes we can draw a circle as follows: But there is a method to draw an ellipse. The canvas does not have a direct method to draw a circle. Style := psSolid // Draw the rectangle Canvas. Bottom := cy + h div 2 // Set the fill color Canvas. FormPaint ( Sender : TObject ) var w, h : Integer // Width and height of the rectangle cx, cy : Integer // center of the form R : TRect // record containing the coordinates of the rectangle's left, top, right, bottom corners begin // Calculate form center cx := Width div 2 cy := Height div 2 // Calculate the size of the rectangle w := Width div 2 h := Height div 2 // Calculate the corner points of the rectangle R. 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.

draw triangle free pascal

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).

  • 2.4 Drawing text with sharp edges (non antialiased).
  • 2.3 Drawing text to an exactly fitting width.











  • Draw triangle free pascal