Difference between revisions of "BezierCurve:evaluate"
(→Make a circle follow a curve) |
(→Examples: The new example tries to do the same thing as the evaluate() function (i.e. it's useless). It also produces the wrong result.) |
||
Line 19: | Line 19: | ||
<source lang="lua"> | <source lang="lua"> | ||
local controlPoints = {125,125, 125,225, 175,125, 225,125} | local controlPoints = {125,125, 125,225, 175,125, 225,125} | ||
− | local curve = love.math.newBezierCurve(controlPoints) | + | local curve = love.math.newBezierCurve(controlPoints) |
function love.draw() | function love.draw() | ||
Line 30: | Line 30: | ||
love.graphics.line(curve:render()) | love.graphics.line(curve:render()) | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
Revision as of 20:25, 16 December 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.
Contents
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 controlPoints = {125,125, 125,225, 175,125, 225,125}
local curve = love.math.newBezierCurve(controlPoints)
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info