GDI Tutorials: Curve-Based Shapes

 Bézier Curves
 A bézier line is an arc that is strictly based on a set number of points instead of on an ellipse. A bézier curve uses at least four points to draw on. A bézier line with four points can be illustrated as follows:

To draw this line (with four points), the compiler would draw a curve from the first to the fourth points. Then it would bend the curve by bringing each middle (half-center) side close to the second and the third points respectively, of course without touching those second and third points. For example, the above bézier curve could have been drawn using the following four points:

PolyBezier(): To draw a bézier curve, the TCanvas provides the PolyBezier() method. Its syntax is:

`void __fastcall PolyBezier(const TPoint* Points, const int Points_Size);`

The Points argument is an array of POINT or TPoint values. The Points_Size argument specifies the number of points that will be used to draw the line minus 1. Here is an example:

 ```//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[4] = { Point(20, 12), Point(88, 246), Point(364, 192), Point(250, 48) }; Canvas->PolyBezier(Pt, 3); } //---------------------------------------------------------------------------```

In the same way, you can draw a series of complicated subsequent lines. This is done by adding reference points to the array. To do this, you must add points in increments of three. After drawing the first curve based on the first four points, to draw the next line, the function would use the fourth point as the starting point. Since the bézier line requires 4 points, you must add three more. You can continue adding points by three to draw the bézier curve. Here is an example:

 ```//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[] = { Point(20, 12), Point(88, 246), Point(364, 192), Point(250, 48), Point(175, 38), Point(388, 192), Point(145, 125) }; Canvas->PolyBezier(Pt, 6); } //---------------------------------------------------------------------------```

PolyBezierTo(): The TCanvas::PolyBezier() method requires at least four points to draw its curve. This is because it needs to know where to start drawing. Another way you can control where the curve would start is by using the TCanvas::PolyBezierTo() method. Its syntax is:

`void __fastcall PolyBezierTo(const TPoint * Points, const int Points_Size);`

The PolyBezierTo() method draws a bézier curve. Its first argument, Points, is a pointer to an array of POINT or TPoint values. This member function requires at least three points. It starts drawing from the current line to the third point. If you do not specify the current line, it would start at the origin (0, 0). The first and the second lines are used to control the curve. The Points_Size argument is the number of points that would be considered minus 1. Here is an example:

 ```//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[] = { Point(320, 120), Point(88, 246), Point(364, 122) }; Canvas->PolyBezierTo(Pt, 2); } //---------------------------------------------------------------------------```