Difference between revisions of "BezierCurve:evaluate"

(Example)
(A better example. (The old example did exactly what BezierCurve:render is for.))
Line 14: Line 14:
 
{{param|number|x|x coordinate of the curve at parameter t.}}
 
{{param|number|x|x coordinate of the curve at parameter t.}}
 
{{param|number|y|y coordinate of the curve at parameter t.}}
 
{{param|number|y|y coordinate of the curve at parameter t.}}
=== Example ===
+
== Examples ==
Get list of coordinate pairs:
+
 
 +
=== Make a circle follow a curve ===
 
<source lang="lua">
 
<source lang="lua">
BezierCurve = love.math.newBezierCurve({25,25, 25,125, 75,25, 125,25})
+
local curve = love.math.newBezierCurve({125,125, 125,225, 175,125, 225,125})
local subdivisions = 2^3
+
 
line = {}
+
function love.draw()
for i = 0, subdivisions do
+
local time    = love.timer.getTime()
local t = i/subdivisions
+
local loopTime = 4
print (t)
+
local t       = (time / loopTime) % 1
local x, y = BezierCurve:evaluate(t)
+
local x, y     = curve:evaluate(t)
table.insert (line, x)
+
 
table.insert (line, y)
+
love.graphics.circle("fill", x, y, 8)
 +
love.graphics.line(curve:render())
 
end
 
end
love.graphics.line(line)
 
 
</source>
 
</source>
  

Revision as of 08:20, 23 November 2021

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

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.

Function

Synopsis

x,y = BezierCurve:evaluate(t)

Arguments

number t
Where to evaluate the curve.

Returns

number x
x coordinate of the curve at parameter t.
number y
y coordinate of the curve at parameter t.

Examples

Make a circle follow a curve

local curve = love.math.newBezierCurve({125,125, 125,225, 175,125, 225,125})

function love.draw()
	local time     = love.timer.getTime()
	local loopTime = 4
	local t        = (time / loopTime) % 1
	local x, y     = curve:evaluate(t)

	love.graphics.circle("fill", x, y, 8)
	love.graphics.line(curve:render())
end

See Also


Other Languages