function clamp(x, min, max)
if min > max then
return math.min(math.max(x, max), min)
else
return math.min(math.max(x, min), max)
end
return x
end
function linear_interpolation(start, end_pos, time)
return (end_pos - start) * time + start
end
anim.lerp = function(start, end_pos, time)
if type(start) == 'userdata' then
local color_data = {0, 0, 0, 0}
for i, color_key in ipairs({'r', 'g', 'b', 'a'}) do color_data[i] = anim.lerp(start[color_key], end_pos[color_key], time) end
return Color.new(unpack(color_data))
end
--[[
Color Animation
local val = return true/false or GlobalVars.realtime % 4 > 2 --Anim enabler
local color = anim.new('test color', val and Color.new(1, 1, 1) or Color.new(0, 0, 0), 0.005) --Anim Color
Move Animation
local val = return true/false or GlobalVars.realtime % 4 > 2 --Anim enabler
local y = anim.new('test y', val and 400 or 500, 0.007) --Anim Strafe setup
local pos = Vector2.new(200, y) --Anim Strafe start
]]--
time = time or 0.005
time = clamp(GlobalVars.frametime * time * 175.0, 0.01, 1.0)
return linear_interpolation(start, end_pos, time)
end
anim.new = function(name, value, time)
if anim.data[name] == nil then
anim.data[name] = value
end
anim.data[name] = anim.lerp(anim.data[name], value, time)
return anim.data[name]
end