Bezier Splines

A Bezier spline is defined by four points, which include two endpoints and two controlling points. Combined, these points define a curve. The two endpoints define the start and end of the curve. The control points serve to "pull" the curve away from the line segment formed by the start and end points.

To draw Bezier splines, use the drawBezier curve method. This method takes an array of Point objects as a parameter. The first four elements of this array define the starting point, two control points, and the end point of the spline.

To draw multiple splines, include three array elements for each spline after the first one. The end point of the first spline serves as the starting point for the next one, and the three array elements define the control points and the end point.

The following code uses the drawBezier method to draw a bezier curve every time the window is resized:

   protected void onPaint(PaintEvent e)
   {
      Point [] pt = new Point[4];
      Rectangle rc = this.getClientRect();
      int right = rc.getRight();
      int bottom = rc.getBottom();
      
      pt[0] = new Point(right / 4, bottom / 2);
      pt[1] = new Point(right / 2, bottom / 4);
      pt[2] = new Point(right / 2, 3 * bottom / 4);
      pt[3] = new Point(3 * right / 4, bottom / 2);
      
      e.graphics.drawBezier(pt);
   }

   protected void onResize(Event e)

   {
      this.invalidate();
   }