Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Vector2 = {}
- local v2mt = {}
- function Vector2.new(X, Y)
- return setmetatable({x = X or 0, y = Y or 0}, v2mt)
- end
- v2mt.__add = function(myVector, otherVector)
- myVector.x = myVector.x + otherVector.x
- myVector.y = myVector.y + otherVector.y
- return myVector
- end
- v2mt.__sub = function(myVector, otherVector)
- myVector.x = myVector.x - otherVector.x
- myVector.y = myVector.y - otherVector.y
- return myVector
- end
- v2mt.__mul = function(scalar, myVector)
- myVector.x = myVector.x * scalar
- myVector.y = myVector.y * scalar
- return myVector
- end
- v2mt.__tostring = function(mytable)
- return "("..mytable.x..", "..mytable.y..")"
- end
- v2mt.__call = function(mytable)
- return Vector2.new(mytable.x, mytable.y)
- end
- local function bezier(t, ...)
- local points = {...}
- local function lerp(v,a,b)
- return v*(b()-a())+a()
- end
- local pts = {}
- for i = 1, #points-1, 1 do
- local a,b = points[i],points[i+1]
- table.insert(pts, lerp(t, a, b))
- end
- if #pts > 1 then
- return bezier(t, table.unpack(pts))
- end
- return table.unpack(pts)
- end
- local pts = {
- Vector2.new(-1,0),
- Vector2.new(0,1),
- Vector2.new(0,-1),
- Vector2.new(1,0)
- }
- local bez = bezier(0.5, table.unpack(pts))
- print(bez)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement