Bezier curves

Your browser does not support the canvas element.

+ click on an empty zone to spawn a point
+ click on a segment to split it in two
+ move points by dragging them
+ move points out of the canvas to delete them

De Casteljeau's algorithm
The demo uses De Casteljeau's algorithm to draw the curves
Here's the algorithm in pseudocode:

P is the array where the control points are stored
Pt is an auxilliary array used by the algorithm

For u := 0 to 1, step 0.01
 Copy the contents of P in Pt
 For i := 0 to #_points
  Decrement #_points_tmp by 1
  For j := 0 to #_points_tmp
   Pt[i] := Pt[i] + u * (Pt[i+1] - Pt[i]);
 Plot Pt[0]

1 comment:

  1. This is awesome! The animation is beautiful.
    It looks like there's a typo in your explanation of De Casteljeau's algorithm:

    In the 6th line of the code ("Pt[i] :=" etc.), all of the instances of i should be changed to j.