eruaaaaaaa

ye

Apr 5th, 2022 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.83 KB | None | 0 0
  1. local Utilities = {}
  2.  
  3. local stringformat = string.format -- // Stored for performance
  4. local mathpi = math.pi
  5. local mathsin = math.sin
  6. local mathcos = math.cos
  7. local mathpow = math.pow
  8. local mathsqrt = math.sqrt
  9. local mathabs = math.abs
  10.  
  11. function Utilities:ExpandTable(Table, Func, Spacing, LastSpacing, StartingTable) -- table.foreach but it goes through all tables
  12.     Table = Table or {}
  13.  
  14.     Spacing = Spacing or 1
  15.     LastSpacing = LastSpacing or " "
  16.     StartingTable = StartingTable or false
  17.     if not StartingTable then
  18.         Func(tostring(Table))
  19.     end
  20.  
  21.  
  22.     for i, v in pairs(Table) do
  23.         Func(stringformat("%s%s %s", LastSpacing, tostring(i), tostring(v)))
  24.         if type(v) == "table" then
  25.             local AddSpacing = LastSpacing  
  26.             for i = 1, Spacing do
  27.                 AddSpacing = AddSpacing .. " "
  28.             end
  29.  
  30.             self:ExpandTable(v, Func, Spacing, AddSpacing, true, StoredString)
  31.         end
  32.     end
  33.  
  34.     return StoredString
  35. end
  36.  
  37. function Utilities:Reverse(Table)
  38.     for i = 1, math.floor(#Table/2) do
  39.         local Temp = Table[i]
  40.         Table[i] = Table[#Table - i + 1]
  41.         Table[#Table - i + 1] = Temp
  42.     end
  43.  
  44.     return Table
  45. end
  46.  
  47. function Utilities:Sort(Table, SortType)
  48.     SortType = SortType or "ascending"
  49.  
  50.     local SortedTable = {}
  51.     for i, v in pairs(Table) do
  52.         SortedTable[i] = v
  53.     end
  54.  
  55.     table.sort(SortedTable)
  56.  
  57.     if SortType == "descending" then
  58.         SortedTable = self:Reverse(SortedTable)
  59.     end
  60.  
  61.     return SortedTable
  62. end
  63.  
  64. Utilities.Easings = {
  65.     easeInSine = function(x)
  66.         return 1 - mathcos((x * mathpi) / 2)
  67.     end,
  68.     easeOutSine = function(x)
  69.         return mathsin((x * mathpi) / 2)
  70.     end,
  71.     easeInOutSine = function(x)
  72.         return -(mathcos(mathpi * x) - 1) / 2
  73.     end,
  74.     easeInQuad = function(x)
  75.         return x^2
  76.     end,
  77.     easeOutQuad = function(x)
  78.         return 1 - (1- x) * (1 - x)
  79.     end,
  80.     easeInOutQuad = function(x)
  81.         return x < 0.5 and 2 * x^2 or 1 - mathpow(-2 * x + 2, 2) / 2
  82.     end,
  83.     easeInCubic = function(x)
  84.         return x^3
  85.     end,
  86.     easeOutCubic = function(x)
  87.         return 1 - mathpow(1 - x, 3)
  88.     end,
  89.     easeInOutCubic = function(x)
  90.         return x < 0.5 and 4 * x^3 or 1 - mathpow(-2 * x + 2, 3) / 2
  91.     end,
  92.     easeInQuart = function(x)
  93.         return x^4
  94.     end,
  95.     easeOutQuart = function(x)
  96.         return 1 - mathpow(1 - x, 4)
  97.     end,
  98.     easeInOutQuart = function(x)
  99.         return x < 0.5 and 8 * x^4 or 1 - mathpow(-2 * x + 2, 4) / 2
  100.     end,
  101.     easeInQuint = function(x)
  102.         return x^5
  103.     end,
  104.     easeOutQuint = function(x)
  105.         return 1 - mathpow(1 - x, 5)
  106.     end,
  107.     easeInOutQuint = function(x)
  108.         return x < 0.5 and 16 * x^5 or 1 - mathpow(-2 * x + 2, 5) / 2
  109.     end,
  110.     easeInExpo = function(x)
  111.         return x == 0 and 0 or mathpow(2, 10 * x - 10)
  112.     end,
  113.     easeOutExpo = function(x)
  114.         return x == 1 and 1 or 1 - mathpow(2, -10 * x)
  115.     end,
  116.     easeInOutExpo = function(x)
  117.         return x == 0 and 0 or x == 1 and 1 or x < 0.5 and mathpow(2, 20 * x - 10) / 2 or (2 - mathpow(2, -20 * x + 10)) / 2
  118.     end,
  119.     easeInCirc = function(x)
  120.         return 1 - mathsqrt(1 - mathpow(x, 2))
  121.     end,
  122.     easeOutCirc = function(x)
  123.         return mathsqrt(1 - mathpow(x - 1, 2))
  124.     end,
  125.     easeInOutCirc = function(x)
  126.         return x < 0.5 and (1 - mathsqrt(1 - mathpow(2 * x, 2))) / 2 or (mathsqrt(1 - mathpow(-2 * x + 2, 2)) + 1) / 2
  127.     end,
  128.     easeInBack = function(x)
  129.         local c1 = 1.70158
  130.         local c3 = c1 + 1
  131.         return c3 * x^3 - c1 * x^2
  132.     end,
  133.     easeOutBack = function(x)
  134.         local c1 = 1.70158
  135.         local c3 = c1 + 1
  136.         return 1 + c3 * mathpow(x - 1, 3) + c1 * mathpow(x - 1, 2)
  137.     end,
  138.     easeInOutBack = function(x)
  139.         local c1 = 1.70158
  140.         local c2 = c1 * 1.525
  141.         return x < 0.5 and (mathpow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2 or (mathpow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 -2) + c2) + 2) / 2
  142.     end,
  143.     easeInElastic = function(x)
  144.         local c4 = (2 * mathpi) / 3
  145.         return x == 0 and 0 or x == 1 and 1 or -mathpow(2, 10 * x - 10) * mathsin((x * 10 - 10.75) * c4)
  146.     end,
  147.     easeOutElastic = function(x)
  148.         local c4 = (2 * mathpi) / 3
  149.         return x == 0 and 0 or x == 1 and 1 or mathpow(2, -10 * x) * mathsin((x * 10 -0.75) * c4) + 1
  150.     end,
  151.     easeInOutElastic = function(x)
  152.         local c5 = (2 * mathpi) / 4.5
  153.         return x == 0 and 0 or x == 1 and 1 or x < 0.5 and -(mathpow(2, 20 * x - 10) * mathsin((20 * x - 11.125) * c5)) / 2 or (mathpow(2, -20 * x + 10) * mathsin((20 * x - 11.125) * c5)) / 2 + 1
  154.     end,
  155.     easeInBounce = function(x) -- bounce took forever cus i waanted it to be one line and failed so i copied it from someone else
  156.         return 1 - Utilities.Easings.easeOutBounce(1 - x)
  157.     end,
  158.     easeOutBounce = function(x)
  159.         if x < 1 / 2.75 then
  160.             return 1 * (7.5625 * x^2)
  161.         elseif x < 2 / 2.75 then
  162.             x = x - (1.5 / 2.75)
  163.             return 1 * (7.5625 * x^2 + 0.75)
  164.         elseif x < 2.5 / 2.75 then
  165.             x = x - (2.25 / 2.75)
  166.             return 1 * (7.5625 * x^2 + 0.9375)
  167.         else
  168.             x = x - (2.625 / 2.75)
  169.             return 1 * (7.5625 * x^2 + 0.984375)
  170.         end
  171.     end,
  172.     easeInOutBounce = function(x)
  173.         if x < 0.5 then
  174.             return Utilities.Easings.easeInBounce(x * 2) * 0.5
  175.         else
  176.             return Utilities.Easings.easeOutBounce(x * 2 - 1) * 0.5 + 1 * 0.5
  177.         end
  178.     end
  179. }
  180.  
  181. function Utilities:CreateEasing(Type, Smoothness, WaitTime, Function, value)
  182.     local table = {};
  183.     function table:Break()
  184.         table.broken = true;
  185.     end
  186.     Type = Type and typeof(Type) == "string" and Type or "easeInCirc"
  187.     Smoothness = Smoothness and typeof(Smoothness) == "number" and Smoothness or 0.5
  188.     Function = Function and typeof(Function) == "function" and Function or function(x) return x end
  189.    
  190.     local Easing = self.Easings[Type] or self.Easings.easeInCirc
  191.     task.spawn(function()
  192.         for i = 1, 1*(Smoothness*100) do
  193.             Function(Easing(i/(Smoothness*100)), value)
  194.             task.wait(0.01)
  195.             if table.broken then break end;
  196.         end
  197.     end)
  198.     return table;
  199. end
  200.  
  201. function Utilities:MoveMouse(Position, Smoothness, Sensitivity, Type)
  202.     Position = Position or {x=0, y=0}
  203.     Smoothness = Smoothness or 0.1
  204.     Sensitivity = Sensitivity or 1
  205.     Type = Type or "easeInSine"
  206. end
  207.  
  208. return Utilities
Add Comment
Please, Sign In to add comment