Advertisement
coderboy

Full Code

Mar 29th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. local termOS = require(script.Parent.Parent.Parent)
  2.  
  3. local nsUIBuffer = {}
  4.     -- res: 20x20 (sq)
  5.     local resolution = 20
  6.     local display = script.Parent.Parent.Parent.Parent.Frame
  7.    
  8.     function nsUIBuffer:createRenderMap()
  9.         termOS.eol()
  10.         termOS.wl("Creating a nsUIImageBuffer")
  11.         termOS.eol()
  12.         termOS.wl("Progress:") 
  13.         termOS.eol()       
  14.        
  15.         -- create uiBuffer
  16.         local uiBuffer = Instance.new("Frame") 
  17.         uiBuffer.Parent = display
  18.         uiBuffer.Size = UDim2.new(1,0,1,0)
  19.         uiBuffer.BackgroundColor3 = Color3.fromRGB(0,0,0)
  20.         uiBuffer.Visible = false
  21.        
  22.         --create uiDisplayMatrix
  23.         local matrix = {}
  24.         local bmp = {x=0,y=0}
  25.         for x=0, resolution, display.Size.X.Scale/resolution do
  26.             bmp.x = bmp.x + 1          
  27.             matrix[tostring(bmp.x)] = {}
  28.             for y=0, resolution, display.Size.Y.Scale/resolution do
  29.                 bmp.y = bmp.y + 1
  30.                 local pixel = Instance.new("Frame")
  31.                 pixel.Size = UDim2.new(display.Size.X.Scale/resolution, display.Size.Y.Scale/resolution)
  32.                 pixel.Position = UDim2.new(x,0,y,0)
  33.                 pixel.BackgroundColor3 = Color3.fromRGB(0,0,0)
  34.                 pixel.BorderSizePixel = 0
  35.                 pixel.Parent = uiBuffer
  36.                 matrix[tostring(bmp.x)][tostring(bmp.x)] = {r=0,g=0,b=0,a=1, o=pixel} -- R G B Alpha (1=Opaque, 0=Transparent) Object          
  37.             end
  38.             local bfr = ""
  39.             -- a * d / c = b
  40.             for j=0, math.floor( ( x * 100 / resolution ) ) do
  41.                 bfr = bfr .. "#"
  42.             end
  43.             for j=0, 100-#bfr do
  44.                 bfr = bfr .. " "
  45.             end
  46.             termOS.wl("[ " .. bfr .. " ]")
  47.             wait()
  48.         end
  49.        
  50.         termOS.eol()
  51.         termOS.wl("Done; clearing TerminalUIBuffer")           
  52.        
  53.         display.buffer:ClearAllChildren()
  54.         display.buffer.Visible = false     
  55.  
  56.         rawset(self, "buffer", uiBuffer)
  57.         rawset(self, "matrix", matrix)
  58.        
  59.         return self
  60.     end
  61.    
  62.     function nsUIBuffer:render(displayMatrix)
  63.         for a,x in pairs(displayMatrix) do
  64.             if (x=={}) then
  65.             else
  66.                 for c,y in pairs(x) do
  67.                     if (y=={}) then
  68.                     else
  69.                         for d,pixel in pairs(y) do
  70.                             if (pixel=={}) then
  71.                             else
  72.                                 local pixel = rawget(self, "matrix")
  73.                                 print(unpack(pixel))
  74.                                 pixel = pixel[tostring(x)][tostring(y)]["o"]
  75.                                 pixel.BackgroundColor3 = Color3.fromRGB(pixel.r,pixel.g,pixel.b)
  76.                             end
  77.                             wait()
  78.                         end
  79.                     end
  80.                     wait()
  81.                 end
  82.             end
  83.             wait()
  84.         end
  85.     end
  86.  
  87. return function(args)
  88.     if #args==1 then
  89.         termOS.eol()
  90.         termOS.wl("This is an API, not an app!")
  91.     else
  92.         return setmetatable(nsUIBuffer,{})
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement