Advertisement
9551

strech2D

Oct 1st, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. function index:strech(x, y)
  2.     local tbl = self
  3.     if not self then
  4.         error("try using : instead of .", 0)
  5.     end
  6.     if type(x) == "number" and type(y) == "number" then
  7.         local strechmap = {}
  8.         local strechmapy = {}
  9.         local final
  10.         local mulx = 1
  11.         local muly = 1
  12.         strechmap["offset"] = tbl.offset
  13.         strechmapy["offset"] = tbl.offset
  14.         for k, v in pairs(tbl) do
  15.             if type(k) == "number" then
  16.                 for k2, v2 in pairs(v) do
  17.                     for i = 1, x do
  18.                         if x > 1 then
  19.                             mulx = x
  20.                         end
  21.                         if not strechmap[k * mulx + i] then
  22.                             strechmap[k * mulx + i] = {}
  23.                         end
  24.                         if not strechmap[k * mulx + i][k2] then
  25.                             strechmap[k * mulx + i][k2] = {}
  26.                         end
  27.                         strechmap[k * mulx + i][k2] = tbl[k][k2]
  28.                     end
  29.                 end
  30.             end
  31.         end
  32.         if y > 1 then
  33.             for k, v in pairs(strechmap) do
  34.                 if type(k) == "number" then
  35.                     for k2, v2 in pairs(v) do
  36.                         for i = 1, y do
  37.                             if y > 1 then
  38.                                 muly = y
  39.                             end
  40.                             if not strechmapy[k] then
  41.                                 strechmapy[k] = {}
  42.                             end
  43.                             if not strechmapy[k][k2 * muly + i] then
  44.                                 strechmapy[k][k2 * muly + i] = {}
  45.                             end
  46.                             strechmapy[k][k2 * muly + i] = strechmap[k][k2]
  47.                         end
  48.                     end
  49.                 end
  50.             end
  51.         end
  52.         if not next(strechmap) then
  53.             strechmap = tbl
  54.         end
  55.         if y > 1 then
  56.             final = strechmapy
  57.         else
  58.             final = strechmap
  59.         end
  60.         return setmetatable(final, getmetatable(tbl))
  61.     else
  62.         return tbl
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement