Advertisement
KrYn0MoRe

pixel printer

Jun 6th, 2020 (edited)
1,923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.28 KB | None | 0 0
  1. local DX = 30
  2. local maxcount = 3
  3. local DY = math.floor((DX/2)+(DX/16))
  4. local PX,PY = 1/DX,1/DY
  5. local spart,screen
  6. local pixels = {}
  7.  
  8. --//=================================\\
  9. --|| SAZERENOS' ARTIFICIAL HEARTBEAT
  10. --\\=================================//
  11.  
  12. ArtificialHB = Instance.new("BindableEvent", script)
  13. ArtificialHB.Name = "ArtificialHB"
  14.  
  15. script:WaitForChild("ArtificialHB")
  16.  
  17. frame = (1/60)
  18. tf = 0
  19. allowframeloss = false
  20. tossremainder = false
  21. lastframe = tick()
  22. script.ArtificialHB:Fire()
  23.  
  24. game:GetService("RunService").Heartbeat:connect(function(s, p)
  25.     tf = tf + s
  26.     if tf >= frame then
  27.         if allowframeloss then
  28.             script.ArtificialHB:Fire()
  29.             lastframe = tick()
  30.         else
  31.             for i = 1, math.floor(tf / frame) do
  32.                 script.ArtificialHB:Fire()
  33.             end
  34.         lastframe = tick()
  35.         end
  36.         if tossremainder then
  37.             tf = 0
  38.         else
  39.             tf = tf - frame * math.floor(tf / frame)
  40.         end
  41.     end
  42. end)
  43.  
  44. function Swait(NUMBER)
  45.     if NUMBER == 0 or NUMBER == nil then
  46.         ArtificialHB.Event:wait()
  47.     else
  48.         for i = 1, NUMBER do
  49.             ArtificialHB.Event:wait()
  50.         end
  51.     end
  52. end
  53.  
  54. --//=================================\\
  55. --\\=================================//
  56.  
  57. function create_screen_pixels()
  58.     spart = Instance.new("Part")
  59.     screen = Instance.new("SurfaceGui")
  60.     spart.Parent = script
  61.     spart.CFrame = CFrame.new(1.15006196, 7.37997007, -0.665921986, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  62.     spart.Orientation = Vector3.new(0, 180, 0)
  63.     spart.Color = Color3.new(0.972549, 0.972549, 0.972549)
  64.     spart.Size = Vector3.new(26.2399158, 14.7599401, 0.151851237)
  65.     spart.Material = Enum.Material.SmoothPlastic
  66.     spart.Anchored = true
  67.     spart.Locked = false
  68.     spart.CanCollide = true
  69.     screen.Parent = spart
  70.     screen.LightInfluence = 1
  71.     screen.ClipsDescendants = true
  72.     screen.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  73.     screen.Adornee = spart
  74.     for Y = 1,DY do
  75.         for X = 1,DX do
  76.             local size = UDim2.new(PX,0,PY,0)
  77.             local offset = UDim2.new(PX*X-PX,0,PY*Y-PY,0)
  78.             local seat = ((Y-1)*DX+X)
  79.             local pixel = Instance.new("Frame")
  80.             pixel.Parent = screen
  81.             pixel.BorderSizePixel = 0
  82.             pixel.BackgroundColor3 = Color3.new(1,1,1)
  83.             pixel.BorderColor3 = Color3.new()
  84.             pixel.Size = size
  85.             pixel.Position = offset
  86.             table.insert(pixels,seat,pixel)
  87.             Swait()
  88.         end
  89.     end
  90. end
  91.  
  92. function create_screen_parts()
  93.     spart = Instance.new("Part")
  94.     screen = Instance.new("Model")
  95.     spart.Parent = script
  96.     spart.CFrame = CFrame.new(1.15006196, 7.37997007, -0.665921986, -1, 0, 0, 0, 1, 0, 0, 0, -1)
  97.     spart.Orientation = Vector3.new(0, 180, 0)
  98.     spart.Color = Color3.new(0.972549, 0.972549, 0.972549)
  99.     spart.Size = Vector3.new(26.2399158, 14.7599401, 0.151851237)
  100.     spart.Material = Enum.Material.SmoothPlastic
  101.     spart.Anchored = true
  102.     spart.Locked = false
  103.     spart.CanCollide = true
  104.     screen.Parent = spart
  105.     for Y = 1,DY do
  106.         for X = 1,DX do
  107.             local _PX,_PY = spart.Size.X/DX,spart.Size.Y/DY
  108.             local size = Vector3.new(_PX,_PY,1)
  109.             local pos = (spart.Position+Vector3.new(-(spart.Size.X/2),(spart.Size.Y/2),0))-Vector3.new(-(_PX*X-_PX/2),_PY*Y-_PY/2,0)
  110.             local seat = ((Y-1)*DX+X)
  111.             local pixel = Instance.new("Part")
  112.             pixel.Parent = screen
  113.             pixel.Material = Enum.Material.SmoothPlastic
  114.             pixel.Color = Color3.new(1,1,1)
  115.             pixel.Size = size
  116.             pixel.Transparency = 0
  117.             pixel.Anchored = true
  118.             pixel.CanCollide = true
  119.             pixel.Locked = true
  120.             pixel.Position = pos
  121.             table.insert(pixels,seat,pixel)
  122.             Swait()
  123.         end
  124.     end
  125. end
  126.  
  127. function clear_screen()
  128.     for i,pixel in pairs(screen:GetChildren()) do
  129.         if pixel then
  130.             pixel.ZIndex = 1
  131.             pixel.BorderColor3 = Color3.new()
  132.             pixel.BorderSizePixel = 0
  133.             pixel.BackgroundTransparency = 1
  134.             pixel.BackgroundColor3 = Color3.new(1,1,1)
  135.         end;
  136.     end;
  137. end
  138.  
  139. function update_screen_ray_pixels()
  140.     for Y = 1,DY do
  141.         spawn(function()
  142.         for X = 1,DX do
  143.             local _PX,_PY = spart.Size.X/DX,spart.Size.Y/DY
  144.             local pos = (spart.Position+Vector3.new(-(spart.Size.X/2),(spart.Size.Y/2),0))-Vector3.new(-(_PX*X-_PX/2),_PY*Y-_PY/2,0)
  145.             local dist = 20
  146.             local ray = Ray.new(pos,((pos+Vector3.new(0,0,1))-pos).Unit*dist)
  147.             local hit,hitpos = workspace:FindPartOnRayWithIgnoreList(ray,{script},true,true)
  148.             local seat = ((Y-1)*DX+X)
  149.             local pixel = pixels[seat]
  150.             if hit and hit.Parent and not hit.Parent:IsA("Accessory") then
  151.                 if pixel then
  152.                     if hit.Name == 'HumanoidRootPart' then
  153.                         hit = hit.Parent:FindFirstChild("Torso") or hit.Parent:FindFirstChild("UpperTorso")
  154.                         if hit then
  155.                             local depth = (dist-hitpos.Z)/5
  156.                             local depth_color = (hitpos.Z/dist)
  157.                             if 1 > depth then
  158.                                 depth = 1
  159.                             end
  160.                             pixel.ZIndex = 1+depth
  161.                             pixel.BorderColor3 = Color3.new(depth_color,depth_color,depth_color)
  162.                             pixel.BorderSizePixel = depth
  163.                             pixel.BackgroundTransparency = hit.Transparency
  164.                             pixel.BackgroundColor3 = hit.Color
  165.                         end
  166.                     else--if 1 > hit.Transparency then
  167.                         local depth = (dist-hitpos.Z)/5
  168.                         local depth_color = (hitpos.Z/dist)
  169.                         if 1 > depth then
  170.                             depth = 1
  171.                         end
  172.                         pixel.ZIndex = 1+depth
  173.                         pixel.BorderColor3 = Color3.new(depth_color,depth_color,depth_color)
  174.                         pixel.BorderSizePixel = depth
  175.                         pixel.BackgroundTransparency = hit.Transparency
  176.                         pixel.BackgroundColor3 = hit.Color
  177.                     end
  178.                 end
  179.             elseif pixel then
  180.                 pixel.ZIndex = 1
  181.                 pixel.BorderColor3 = Color3.new()
  182.                 pixel.BorderSizePixel = 0
  183.                 pixel.BackgroundTransparency = 1
  184.                 pixel.BackgroundColor3 = Color3.new(1,1,1)
  185.             end
  186.             Swait()
  187.         end
  188.         end)
  189.         Swait()
  190.     end
  191. end
  192.  
  193. function create_ray(X,Y,_PX,_PY,pos,count,t)
  194.     local dist = 20/maxcount
  195.     local ray = Ray.new(pos,((pos+Vector3.new(0,0,1))-pos).Unit*dist)
  196.     local hit,hitpos = workspace:FindPartOnRayWithIgnoreList(ray,{script,table.unpack(t)},true,true)
  197.     local seat = ((Y-1)*DX+X)
  198.     local pixel = pixels[seat]
  199.     local found = false
  200.     if hit and hit.Parent and not hit.Parent:IsA("Accessory") then
  201.         if pixel then
  202.             if hit.Name == 'HumanoidRootPart' then
  203.                 hit = hit.Parent:FindFirstChild("Torso") or hit.Parent:FindFirstChild("UpperTorso")
  204.                 if hit then
  205.                     found = true
  206.                     pixel.Material = hit.Material
  207.                     pixel.Color = hit.Color
  208.                     pixel.Transparency = hit.Transparency
  209.                 end
  210.             elseif 1 > hit.Transparency then
  211.                 found = true
  212.                 pixel.Material = hit.Material
  213.                 pixel.Color = hit.Color
  214.                 pixel.Transparency = hit.Transparency
  215.             end
  216.         end
  217.     elseif pixel then
  218.         pixel.Material = Enum.Material.SmoothPlastic
  219.         pixel.Color = Color3.new(1,1,1)
  220.         pixel.Transparency = 0
  221.     end
  222.     --Swait()
  223.     count = count + 1
  224.     if maxcount >= count and not found then
  225.         create_ray(X,Y,_PX,_PY,hitpos,count,{table.unpack(t),hit})
  226.     end
  227. end
  228.  
  229. function update_screen_ray_parts()
  230.     for Y = 1,DY do
  231.         spawn(function()
  232.         for X = 1,DX do
  233.             local _PX,_PY = spart.Size.X/DX,spart.Size.Y/DY
  234.             local pos = (spart.Position+Vector3.new(-(spart.Size.X/2),(spart.Size.Y/2),0))-Vector3.new(-(_PX*X-_PX/2),_PY*Y-_PY/2,0)
  235.             create_ray(X,Y,_PX,_PY,pos,1,{})
  236.         end
  237.         end)
  238.         Swait()
  239.     end
  240. end
  241.  
  242. --create_screen_parts()
  243. create_screen_pixels()
  244.  
  245. game:GetService("RunService").Stepped:Connect(function()
  246.     --clear_screen()
  247.     --update_screen_ray_parts()
  248.     update_screen_ray_pixels()
  249. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement