|
| 29 Jul 2016 01:51 PM |
use this module> local module = {}
-- t = time == how much time has to pass for the tweening to complete -- b = begin == starting property value -- c = change == ending - beginning -- d = duration == running time. How much time has passed *right now*
easingStyles = { --Linear Linear = function(t, b, c, d) return c * t / d + b end, --Quad inQuad = function(t, b, c, d) return c * math.pow(t / d, 2) + b end, outQuad = function(t, b, c, d) t = t / d return -c * t * (t - 2) + b end, inOutQuad = function(t, b, c, d) t = t / d * 2 if t < 1 then return c / 2 * math.pow(t, 2) + b end return -c / 2 * ((t - 1) * (t - 3) - 1) + b end, outInQuad = function(t, b, c, d) if t < d / 2 then return easingStyles.outQuad(t * 2, b, c / 2, d) end return easingStyles.inQuad((t * 2) - d, b + c / 2, c / 2, d) end, --Cubic inCubic = function(t, b, c, d) return c * math.pow(t / d, 3) + b end, outCubic = function(t, b, c, d) return c * (math.pow(t / d - 1, 3) + 1) + b end, inOutCubic = function(t, b, c, d) t = t / d * 2 if t < 1 then return c / 2 * t * t * t + b end t = t - 2 return c / 2 * (t * t * t + 2) + b end, outInCubic = function(t, b, c, d) if t < d / 2 then return easingStyles.outCubic(t * 2, b, c / 2, d) end return easingStyles.inCubic((t * 2) - d, b + c / 2, c / 2, d) end, --Quart inQuart = function(t, b, c, d) return c * math.pow(t / d, 4) + b end, outQuart = function(t, b, c, d) return -c * (math.pow(t / d - 1, 4) - 1) + b end, inOutQuart = function(t, b, c, d) t = t / d * 2 if t < 1 then return c / 2 * math.pow(t, 4) + b end return -c / 2 * (math.pow(t - 2, 4) - 2) + b end, outInQuart = function(t, b, c, d) if t < d / 2 then return easingStyles.outQuart(t * 2, b, c / 2, d) end return easingStyles.inQuart((t * 2) - d, b + c / 2, c / 2, d) end, --Quint inQuint = function(t, b, c, d) return c * math.pow(t / d, 5) + b end, outQuint = function(t, b, c, d) return c * (math.pow(t / d - 1, 5) + 1) + b end, inOutQuint = function(t, b, c, d) t = t / d * 2 if t < 1 then return c / 2 * math.pow(t, 5) + b end return c / 2 * (math.pow(t - 2, 5) + 2) + b end, outInQuint = function(t, b, c, d) if t < d / 2 then return easingStyles.outQuint(t * 2, b, c / 2, d) end return easingStyles.inQuint((t * 2) - d, b + c / 2, c / 2, d) end, --Sine inSine = function(t, b, c, d) return -c * math.cos(t / d * (math.pi / 2)) + c + b end, outSine = function(t, b, c, d) return c * math.sin(t / d * (math.pi / 2)) + b end, inOutSine = function(t, b, c, d) return -c / 2 * (math.cos(math.pi * t / d) - 1) + b end, outInSine = function(t, b, c, d) if t < d / 2 then return easingStyles.outSine(t * 2, b, c / 2, d) end return easingStyles.inSine((t * 2) -d, b + c / 2, c / 2, d) end, --Expo inExpo = function(t, b, c, d) if t == 0 then return b end return c * math.pow(2, 10 * (t / d - 1)) + b - c * 0.001 end, outExpo = function(t, b, c, d) if t == d then return b + c end return c * 1.001 * (-math.pow(2, -10 * t / d) + 1) + b end, inOutExpo = function(t, b, c, d) if t == 0 then return b end if t == d then return b + c end t = t / d * 2 if t < 1 then return c / 2 * math.pow(2, 10 * (t - 1)) + b - c * 0.0005 end return c / 2 * 1.0005 * (-math.pow(2, -10 * (t - 1)) + 2) + b end, outInExpo = function(t, b, c, d) if t < d / 2 then return easingStyles.outExpo(t * 2, b, c / 2, d) end return easingStyles.inExpo((t * 2) - d, b + c / 2, c / 2, d) end, --Circ inCirc = function(t, b, c, d) return(-c * (math.sqrt(1 - math.pow(t / d, 2)) - 1) + b) end, outCirc = function(t, b, c, d) return(c * math.sqrt(1 - math.pow(t / d - 1, 2)) + b) end, inOutCirc = function(t, b, c, d) t = t / d * 2 if t < 1 then return -c / 2 * (math.sqrt(1 - t * t) - 1) + b end t = t - 2 return c / 2 * (math.sqrt(1 - t * t) + 1) + b end, outInCirc = function(t, b, c, d) if t < d / 2 then return easingStyles.outCirc(t * 2, b, c / 2, d) end return easingStyles.inCirc((t * 2) - d, b + c / 2, c / 2, d) end, --Back outBack = function(t, b, c, d, s) s = s or 1.2 t = t / d - 1 return c * (t * t * ((s + 1) * t + s) + 1) + b end, inBack = function(t, b, c, d, s) s = s or 1.70158 t = t / d return c * t * t * ((s + 1) * t - s) + b end, inOutBack = function(t, b, c, d, s) s = (s or 1.70158) * 1.525 t = t / d * 2 if t < 1 then return c / 2 * (t * t * ((s + 1) * t - s)) + b end t = t - 2 return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b end, outInBack = function(t, b, c, d, s) if t < d / 2 then return easingStyles.outBack(t * 2, b, c / 2, d, s) end return easingStyles.inBack((t * 2) - d, b + c / 2, c / 2, d, s) end, --bounce outBounce = function(t, b, c, d) t = t / d if t < 1 / 2.75 then return c * (7.5625 * t * t) + b end if t < 2 / 2.75 then t = t - (1.5 / 2.75) return c * (7.5625 * t * t + 0.75) + b elseif t < 2.5 / 2.75 then t = t - (2.25 / 2.75) return c * (7.5625 * t * t + 0.9375) + b end t = t - (2.625 / 2.75) return c * (7.5625 * t * t + 0.984375) + b end, inBounce = function(t, b, c, d) return c - easingStyles.outBounce(d - t, 0, c, d) + b end, inOutBounce = function(t, b, c, d) if t < d / 2 then return easingStyles.inBounce(t * 2, 0, c, d) * 0.5 + b end return easingStyles.outBounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b end, outInBounce = function(t, b, c, d) if t < d / 2 then return easingStyles.outBounce(t * 2, b, c / 2, d) end return easingStyles.inBounce((t * 2) - d, b + c / 2, c / 2, d) end }
module.interpolateWeld = function(Weld,NewC1,easingStyle,Duration) spawn(function() math.randomseed(tick() * math.random() * math.random()) easingStyle = easingStyle or 'Linear' local NewCode = math.random(-1e9,1e9) if Weld:FindFirstChild('TweenIndication') then Weld:FindFirstChild('TweenIndication').Value = NewCode else local tweenIndication = Instance.new('NumberValue',Weld) tweenIndication.Name = 'TweenIndication' tweenIndication.Value = NewCode end local tweenIndication = Instance.new('NumberValue',Weld) local StartTime = tick() local StartC1 = Weld.C1 while game:GetService('RunService').RenderStepped:wait() do if Weld:FindFirstChild('TweenIndication').Value ~= NewCode then break end local alpha if tick() >= StartTime + Duration then alpha = 1 else alpha = (tick() - StartTime)/Duration end Weld.C1 = StartC1:lerp(NewC1,easingStyles[easingStyle](alpha,0,1,1)) if tick() >= StartTime + Duration or Weld:FindFirstChild('TweenIndication').Value ~= NewCode then break end end end) end
module.OffsetInterpolate = function(Weld,NewC0,easingStyle,Duration) spawn(function() easingStyle = easingStyle or 'Linear' math.randomseed(tick() * math.random() * math.random()) local NewCode = math.random(-1e9,1e9) if Weld:FindFirstChild('TweenC0') then Weld:FindFirstChild('TweenC0').Value = NewCode else local tweenIndication = Instance.new('NumberValue',Weld) tweenIndication.Name = 'TweenC0' tweenIndication.Value = NewCode end local tweenIndication = Instance.new('NumberValue',Weld) local StartTime = tick() local StartC0 = Weld.C0 while game:GetService('RunService').RenderStepped:wait() do if Weld:FindFirstChild('TweenC0').Value ~= NewCode then break end local alpha if tick() >= StartTime + Duration then alpha = 1 else alpha = (tick() - StartTime)/Duration end Weld.C0 = StartC0:lerp(NewC0,easingStyles[easingStyle](alpha,0,1,1)) if tick() >= StartTime + Duration or Weld:FindFirstChild('TweenC0').Value ~= NewCode then break end end end) end
module.Styles = easingStyles
return module
im a mlg |
|
|
| Report Abuse |
|