Advertisement
XZTablets

Drawing Module

May 28th, 2020
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. -- Module
  2. local PNG_Module = {}
  3. PNG_Module.__index = PNG_Module
  4.  
  5. -- Services
  6. local Players = game:GetService("Players")
  7. local HttpService = game:GetService("HttpService")
  8.  
  9. -- Resources Folder
  10. local Resources = script:WaitForChild("Resources", math.huge)
  11.  
  12. -- Assets
  13. local Assets = Resources:WaitForChild("Assets", math.huge)
  14.  
  15. local Cleaner = Assets:WaitForChild("Cleaner", math.huge)
  16.  
  17. local Frame = Assets:WaitForChild("Drawing_Frame", math.huge)
  18. local Holder = Frame:WaitForChild("Pixels", math.huge)
  19.  
  20. local Pixel = Assets:WaitForChild("Pixel", math.huge)
  21. local Row = Assets:WaitForChild("Row", math.huge)
  22.  
  23. -- Modules
  24. local Modules = Resources:WaitForChild("Modules", math.huge)
  25. local Drawing = require(Modules:WaitForChild("Drawing", math.huge))
  26.  
  27. -- Function
  28. function PNG_Module:drawImage(Image_Url, Size, Color, Anchor, Position)
  29.    
  30.     -- Failsafes
  31.     assert(pcall(HttpService.GetAsync, HttpService, "https://www.google.com/"), "Http isn't enabled on this game.")
  32.     assert(Image_Url ~= nil, "Image Url wasn't provided.")
  33.    
  34.     -- Config
  35.     local Image = HttpService:GetAsync(Image_Url)
  36.     local Pixel_Size = (rawequal(type(Size), "number")) and (Size) or 1
  37.     local Transparent_Color = (rawequal(typeof(Color), "Color3")) and (Color) or Color3.fromRGB(255, 255, 255)
  38.     local Anchor_Point = (rawequal(typeof(Anchor), "Vector2")) and (Anchor) or Vector2.new(.5, .5)
  39.     local Image_Position = (rawequal(typeof(Position), "UDim2")) and (Position) or UDim2.new(.5, 0, .5, 0)
  40.    
  41.     -- Settings
  42.     Holder.AnchorPoint = Anchor_Point
  43.     Holder.Position = Image_Position
  44.    
  45.     Pixel.Size = UDim2.new(0, Pixel_Size, 0, Pixel_Size)
  46.    
  47.     Row.Size = UDim2.new(0, Pixel_Size, 1, 0)
  48.    
  49.     -- Image Processing
  50.     local Result = Drawing.new(Image)
  51.     local Pixels = {}
  52.    
  53.     for X = 1, Result.Width do
  54.         local Table = {}
  55.        
  56.         for Y = 1, Result.Height do
  57.             local Color, Alpha = Drawing:GetPixel(Result, X, Y)
  58.             table.insert(Table, Color)
  59.         end
  60.        
  61.         local New_Row = Row:Clone()
  62.         New_Row.Parent = Holder
  63.        
  64.         for _, Color in next, Table do
  65.             local New_Pixel = Pixel:Clone()
  66.             New_Pixel.Parent = New_Row
  67.             New_Pixel.BackgroundColor3 = Color
  68.            
  69.             if (Color == Transparent_Color) then
  70.                 New_Pixel.BackgroundTransparency = 1
  71.             end
  72.         end
  73.        
  74.     end
  75.    
  76.     -- Image Display
  77.     local Display_Image = function(Index, Object)
  78.         local Player = (type(Index ~= "userdata")) and (Object) or (Index)
  79.         local PlayerGui = Player:FindFirstChildOfClass("PlayerGui")
  80.         Frame:Clone().Parent = PlayerGui
  81.     end
  82.    
  83.     local Clean_Image = function(Index, Object)
  84.         local Player = (type(Index ~= "userdata")) and (Object) or (Index)
  85.         local Backpack = Player:FindFirstChildOfClass("Backpack")
  86.         local Script = Cleaner:Clone()
  87.         Script.Parent = Backpack
  88.         Script.Disabled = false
  89.     end
  90.    
  91.     -- Display Connection  
  92.     if (_G.Drawing_Connection) then
  93.         _G.Drawing_Connection:Disconnect()
  94.         table.foreach(Players:GetPlayers(), Clean_Image)
  95.     end
  96.    
  97.     table.foreach(Players:GetPlayers(), Display_Image)
  98.     _G.Drawing_Connection = Players.PlayerAdded:Connect(Display_Image)
  99. end
  100.  
  101. return setmetatable({}, PNG_Module)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement