The "api":
Bezier.new(points)
Creates a new Bézier curve. Points is a table of x,y pairs defining the control polygon of the curve.
Example:
Code: Select all
b = Bezier.new{10,400, 100,100, 400,90, 490,380}
Returns an identical curve.
Bezier:Bezier:controlPolygon(min,max)
Returns the control points from min to max. If min and max are omitted, they default to min = 1, max = all.
This in addition with unpack() can be used to draw the control polygon:
Example
Code: Select all
love.graphics.line(unpack(b:controlPolygon())
Evaluate the curve with parameter t. t has to fulfill 0 <= t <= 1. This can be used to move an actor on a Bézier-path.
Bezier:degreeUp()
Increases the degree of the curve, that is #control-points - 1. It returns nothing and alters the current bezier-curve.
Bezier:subdivide(t)
Subdivide the curve with weight t. If t is omitted, it defaults to 0.5. The subdivided curve is returned.
Subdivision is the core of the drawing routine.
Example
Code: Select all
b = b:subdivide(.8) -- will subdivide the curve with more points to the end
Returns the derivation of the curve. The derivation is one degree lower than the original curve. Not sure how you may want to use this, but included it anyway
Bezier:polygon(k)
Returns an approximation to the Bézier-curve. If k is omitted, it defaults to 3. 3 to 5 is usually a good choice for visualizing the curve.
Example
Code: Select all
polygon = b:polygon(4)
function love.graphics.draw()
love.graphics.line(unpack(polygon))
end
Draws the curve. As this evaluates Bezier:polygon(k), you should really not use this with a combination of high k and degree of the curve. Use the above instead.
I also attached a demo where you can play with the different functions. Have fun
Next item on the is B-Spline curves (with interpolating and periodic b-splines. Stay tuned)
See attachment below