ΞΜΜΜ̈ˆˆ¬ͺͺͺ¬ˆˆˆ¬ΜΜΜ¬ΜΐΜ¬ΜΐΜ¬ΜΐΜΜΜμΜξͺͺΐΐξΜ¬ΐΜΐ¬ΐΐΐ¬ΐΐΐ¬ΐΐΞΜΜΜ̈ˆˆ¬ͺͺͺ¬ˆˆˆ¬ΜΜΜ¬ΜΜΜ¬ΜΐΜ¬ΜΐΜΜΜμΜξͺͺΐΐξΜ¬ΐΜΜ¬ΐΐΐ¬ΐΐΐ¬ΐΐ¬ΜΜΜ¬ͺͺͺ¬ͺ¬ͺ¬ͺΚΜ¬ͺͺͺŒˆˆˆΜΐΜΞΜΜΞΜ¬Μͺͺΐμ¬ͺΐξͺͺΐξͺͺΐΜξΐμξΜΜξξ¬ΜΜΜ¬ͺͺͺ¬ͺ¬ͺ¬ͺΚΜ¬ͺͺͺŒˆˆˆΜΐΜΞΜΜΞΜ¬Μͺͺΐμ¬ͺΐξͺͺΐξͺͺΐΜξΐμξΜΜξξ >Μ;   ͺͺͺͺ   ͺ     ͺ   ͺ  ͺ          ͺ      ͺ                                                                                                                 ͺ          ͺ              ͺ   ͺͺ   ͺͺͺͺ     ΐΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜ ΐΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜ ΐΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜΜ ΜΜ̈ˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜΜΜ̈ˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜΜΜ̈ˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ¬ͺˆˆˆˆˆˆˆˆˆˆˆˆˆ¨ͺΐΜΜ¬ͺˆˆˆˆˆˆˆˆˆˆˆˆˆ¨ͺΐΜΜ¬ͺˆˆˆˆˆˆˆˆˆˆˆˆˆ¨ͺΐΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΐΜΜΜΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΐΜΜΜΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΐΜΜΜΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΐΜΜΜΜΐΜΜ¬ͺΐΜΐΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΜΜΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΜΜΜΜ¬ͺΜΜΜΜΜΜΜΜΜΜΜΜΜ¬ͺΜΜΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ Μ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ Μ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ Μ¬ͺͺͺͺΜ¬ͺͺͺͺΜ¬ͺͺͺͺΐΜΜ¬ͺͺͺͺΜ¬ͺͺͺͺΜ¬ͺͺͺͺΐΜΜ¬ͺͺͺͺΜ¬ͺͺͺͺΜ¬ͺͺͺͺΐΜΜ¬ͺͺͺͺͺΚΜΜΜΜͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺΚΜΜΜΜͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺΚΜΜΜΜͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜΜ¬ͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺͺΐΜ̌ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜ̌ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜ̌ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆΜΜΜΜΜΜΐΜΜΜΜΐΜΜ ΜΜΜΐΜΜΜΜΐΜΜ ΜΜΜΐΜΜΜΜΐΜΜ ΐΜΜΜΜΜΜΜΐΜΜΜΜΜΜΜΐΜΜΜΜΜΜΜΐΜΜΜΜΜΜΜΐΜΜΜΜΜΜΜΐΜΜΜΜΜΜΜž -- title: Easy Ease -- author: Sava -- desc: Small library for easy, automatic interpolation! -- license: MIT License -- version: 0.1 -- script: lua ------------- START OF LIBRARY --------------- local Interpolated = {} Interpolated.__index = Interpolated function Interpolated.new(val, len, func) local obj = { cur = val or 0, next = val or 0, value = val or 0, setT = time(), len = len or 1000, easeFunc = func or linear } return setmetatable(obj, Interpolated) end function Interpolated:__call(a, b) if a == nil then Interpolated.update(self) return self.value else self.cur = b and self.value or self.next self.next = a self.setT = time() Interpolated.update(self) return self.value end end function Interpolated.update(a) a.value = a.easeFunc(a.cur, a.next, math.min((time()-a.setT)/a.len, 1)) end -- Functions from easings.net function linear(a, b, t) return a+(b-a)*t end function easeIn(a, b, t) return linear(a, b, t*t) end function easeOut(a, b, t) return linear(a, b, 1-(1-t)*(1-t)) end function easeInOut(a, b, t) return linear(a, b, t < 0.5 and 2*t*t or 1-math.pow(-2*t+2,2)/2) end ------------- END OF LIBRARY --------------- ------------- Small documentation -- You can call x=Interpolated.new() -- To create a new value -- Examples: x=Interpolated.new() -- starting value = 0, length (ms) = 1000, function = linear x=Interpolated.new(100) -- starting value = 100 x=Interpolated.new(0, 100) -- starting value = 0, length (ms) = 100 x=Interpolated.new(10, 100, easeOut) -- starting value = 10, length (ms) = 100, function = easeOut x=Interpolated.new(-100, 10, easeIn) -- starting value = -100, length (ms) = 10, function = easeIn -- The ending value gets set to the value of the starting one -- You can change the easing function and the length on the fly with: x.easeFunc = easeInOut -- and x.len = 1000 -- All built-in interpolation functions: -- linear, easeIn, easeOut, easeInOut -- You can put your own, it would have to be in the form of: -- function (a, b, t) -- and return a value for the interpolation -- To set the ending value of the value you can call x(100) -- end position = 100 -- You can also use a second argument to specify -- if you want to set the start to the current value -- or the previous ending value -- Examples: -- Current = 500, start = 0, end = 1000 x(2000) -- end position = 2000, start = 1000 x(2000, true) -- end position = 2000, start = 500 -- Current = 300, start = 0, end = 500 x(100) -- end position = 100, start = 500 x(100, true) -- end position = 100, start = 300 -- To get the current value you can call x() -- That's it ------------- Example -- Create new Interpolated values x=Interpolated.new(100, 300, easeOut) y=Interpolated.new(80, 300, easeOut) function TIC() -- Use y(val) to set the ending position of y to y()-10 -- Where y() is the current value of y if btnp(0) then y(y()-10) end if btnp(1) then y(y()+10) end -- Same here, just for x if btnp(2) then x(x()-10) end if btnp(3) then x(x()+10) end cls(0) -- Use x() and y() to get the current positions spr(1,x(),y(),14,3,0,0,2,2) for i=0, 75 do line(i-1, 75-linear(0, 75, (i-1)/75), i, 75-linear(0, 75, i/75), 10) end for i=0, 75 do line(i-1+75, 75-easeIn(0, 75, (i-1)/75), i+75, 75-easeIn(0, 75, i/75), 10) end for i=0, 75 do line(i-1+150, 75-easeOut(0, 75, (i-1)/75), i+150, 75-easeOut(0, 75, i/75), 10) end end