Revision Difference
math.QuadraticBezier#551369
<cat>libraryfunc</cat>⤶
<function name="QuadraticBezier" parent="math" type="libraryfunc">⤶
<description>Lerp point between 3 control points with quadratic bezier.⤶
<note>There is cubic function <page>math.CubicBezier</page> which works with 4 control points.</note>⤶
</description>⤶
<realm>Shared and Menu</realm>⤶
<added>2023.08.03</added>⤶
<file line="270-L276">lua/includes/extensions/math.lua</file>⤶
<args>⤶
<arg name="frac" type="number">The fraction for finding the result. This number is clamped between 0 and 1.</arg>⤶
<arg name="p0" type="Vector">First control point</arg>⤶
<arg name="p1" type="Vector">Tangent</arg>⤶
<arg name="p2" type="Vector">Second control point</arg>⤶
</args>⤶
<rets>⤶
<ret name="" type="Vector">Point between control points at the specified fraction</ret>⤶
</rets>⤶
</function>⤶
⤶
<example>⤶
<description>Demonstrates the use of this function.</description>⤶
<code>⤶
local points = {⤶
Vector( 128, 128 ),⤶
Vector( 384, 128 ),⤶
Vector( 384, 384 )⤶
}⤶
⤶
hook.Add( "HUDPaint", "math.QuadraticBezier", function()⤶
local frac = RealTime() % 1⤶
local point = math.QuadraticBezier( frac, unpack( points ) )⤶
⤶
surface.SetDrawColor( 255, 255, 0 )⤶
surface.DrawRect( point.x - 4, point.y - 4, 8, 8 )⤶
⤶
surface.DrawRect( points[1].x - 4, points[1].y - 4, 8, 8 )⤶
surface.DrawRect( points[2].x - 4, points[2].y - 4, 8, 8 )⤶
surface.DrawRect( points[3].x - 4, points[3].y - 4, 8, 8 )⤶
end )⤶
</code>⤶
<output>⤶
<image src="https://i.imgur.com/LiYCgAS.gif"/>⤶
</output>⤶
</example>⤶
⤶