Skip to main content

BezierCurve

Description:

  A Bézier curve object that can evaluate and render Bézier curves of arbitrary degree.

type​

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: BezierCurve): string

Returns:

Return TypeDescription
stringThe type as a string.

Of​

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: BezierCurve, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release​

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: BezierCurve): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

getDegree​

Type: Function.

Description:

  Get degree of the Bézier curve. The degree is equal to number-of-control-points - 1.

Signature:

getDegree: function(self: BezierCurve): integer

Returns:

Return TypeDescription
integerDegree of the Bézier curve.

getDerivative​

Type: Function.

Description:

  Get the derivative of the Bézier curve. This function can be used to rotate sprites moving along a curve in the direction of the movement and compute the direction perpendicular to the curve at some parameter t.

Signature:

getDerivative: function(self: BezierCurve): BezierCurve

Returns:

Return TypeDescription
BezierCurveThe derivative curve.

getControlPoint​

Type: Function.

Description:

  Get coordinates of the i-th control point. Indices start with 1.

Signature:

getControlPoint: function(self: BezierCurve, index: integer): number, number

Parameters:

ParameterTypeDescription
indexintegerIndex of the control point.

Returns:

Return TypeDescription
numberPosition of the control point along the x axis.
numberPosition of the control point along the y axis.

setControlPoint​

Type: Function.

Description:

  Set coordinates of the i-th control point. Indices start with 1.

Signature:

setControlPoint: function(self: BezierCurve, index: integer, x: number, y: number)

Parameters:

ParameterTypeDescription
indexintegerIndex of the control point.
xnumberPosition of the control point along the x axis.
ynumberPosition of the control point along the y axis.

insertControlPoint​

Type: Function.

Description:

  Insert control point as the new i-th control point. Existing control points from i onwards are pushed back by 1. Indices start with 1. Negative indices wrap around: -1 is the last control point, -2 the one before the last, etc.

Signature:

insertControlPoint: function(self: BezierCurve, x: number, y: number, index?: integer)

Parameters:

ParameterTypeDescription
xnumberPosition of the control point along the x axis.
ynumberPosition of the control point along the y axis.
indexintegerIndex of the control point. (Default: -1.)

removeControlPoint​

Type: Function.

Description:

  Removes the specified control point.

Signature:

removeControlPoint: function(self: BezierCurve, index: integer)

Parameters:

ParameterTypeDescription
indexintegerThe index of the control point to remove.

getControlPointCount​

Type: Function.

Description:

  Get the number of control points in the Bézier curve.

Signature:

getControlPointCount: function(self: BezierCurve): integer

Returns:

Return TypeDescription
integerThe number of control points.

translate​

Type: Function.

Description:

  Move the Bézier curve by an offset.

Signature:

translate: function(self: BezierCurve, x: number, y: number)

Parameters:

ParameterTypeDescription
xnumberOffset along the x axis.
ynumberOffset along the y axis.

rotate​

Type: Function.

Description:

  Rotate the Bézier curve by an angle.

Signature:

rotate: function(self: BezierCurve, angle: number, origin_x?: number, origin_y?: number)

Parameters:

ParameterTypeDescription
anglenumberRotation angle in radians.
origin_xnumberX coordinate of the rotation center. (Default: 0.)
origin_ynumberY coordinate of the rotation center. (Default: 0.)

scale​

Type: Function.

Description:

  Scale the Bézier curve by a factor.

Signature:

scale: function(self: BezierCurve, scale: number, origin_x?: number, origin_y?: number)

Parameters:

ParameterTypeDescription
scalenumberScale factor.
origin_xnumberX coordinate of the scaling center. (Default: 0.)
origin_ynumberY coordinate of the scaling center. (Default: 0.)

evaluate​

Type: Function.

Description:

  Evaluate Bézier curve at parameter t. The parameter must be between 0 and 1 (inclusive). This function can be used to move objects along paths or tween parameters. However it should not be used to render the curve, see BezierCurve:render for that purpose.

Signature:

evaluate: function(self: BezierCurve, time: number): number, number

Parameters:

ParameterTypeDescription
timenumberWhere to evaluate the curve.

Returns:

Return TypeDescription
numberx coordinate of the curve at parameter t.
numbery coordinate of the curve at parameter t.

getSegment​

Type: Function.

Description:

  Gets a BezierCurve that corresponds to the specified segment of this BezierCurve.

Signature:

getSegment: function(self: BezierCurve, start: number, finish: number): BezierCurve

Parameters:

ParameterTypeDescription
startnumberThe starting point along the curve. Must be between 0 and 1.
finishnumberThe end of the segment. Must be between 0 and 1.

Returns:

Return TypeDescription
BezierCurveA BezierCurve that corresponds to the specified segment.

render​

Type: Function.

Description:

  Get a list of coordinates to be used with love.graphics.line. This function samples the Bézier curve using recursive subdivision. You can control the recursion depth using the depth parameter. If you are just interested to know the position on the curve given a parameter, use BezierCurve:evaluate.

Signature:

render: function(self: BezierCurve, accuracy?: integer): {number}

Parameters:

ParameterTypeDescription
accuracyintegerNumber of recursive subdivision steps. (Default: 5.)

Returns:

Return TypeDescription
{number}List of x,y-coordinate pairs of points on the curve.

renderSegment​

Type: Function.

Description:

  Get a list of coordinates on a specific part of the curve, to be used with love.graphics.line. This function samples the Bézier curve using recursive subdivision. You can control the recursion depth using the depth parameter. If you are just need to know the position on the curve given a parameter, use BezierCurve:evaluate.

Signature:

renderSegment: function(self: BezierCurve, start: number, finish: number, accuracy?: integer): {number}

Parameters:

ParameterTypeDescription
startnumberThe starting point along the curve. Must be between 0 and 1.
finishnumberThe end of the segment to render. Must be between 0 and 1.
accuracyintegerNumber of recursive subdivision steps. (Default: 5.)

Returns:

Return TypeDescription
{number}List of x,y-coordinate pairs of points on the specified part of the curve.