Prehistoricman

CIF image render script

Jan 27th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. resx = 25
  2. resy = 50
  3. file = [[THIS IS WHERE THE IMAGE GOES]]
  4. currentpixel = {1, 0}
  5. pixelsize = 4
  6. pxnumwait = 1
  7.  
  8. --takes the lines out of the string 'file'
  9. newfile = ""
  10. enter = "\n"
  11. for i = 1, #file do
  12. if string.sub(file, i, i) ~= enter then
  13. newfile = newfile..string.sub(file, i, i)
  14. end end
  15. file = newfile
  16.  
  17. function render(a,r,g,b) --makes a pixel
  18. pixel = Instance.new("TextLabel", script.Parent)
  19. pixel.Name = table.concat(currentpixel, ",")
  20. pixel.BorderSizePixel = 0
  21. pixel.BackgroundColor3 = Color3.new(r/255, g/255, b/255)
  22. pixel.BackgroundTransparency = a/255
  23. pixel.Position = UDim2.new(0, 20 + (currentpixel[1]-1) * pixelsize, 0, 60 + currentpixel[2] * pixelsize)
  24. pixel.Size = UDim2.new(0, pixelsize, 0, pixelsize)
  25. pixel.Text = ""
  26. currentpixel[1] = currentpixel[1] + 1
  27. if currentpixel[1] == resx + 1 then
  28. currentpixel[1] = 1
  29. currentpixel[2] = currentpixel[2] + 1
  30. end end
  31.  
  32. function getpicture() --interprets the picture and renders it with function 'render'
  33. pixels = {}
  34. for i = 1, #file, 12 do
  35. table.insert(pixels, string.sub(file, i, i+11))
  36. end
  37. for i = 1, #pixels do
  38. if math.floor(i/pxnumwait) == i/pxnumwait then
  39. wait()
  40. end
  41. render(string.sub(pixels[i], 10, 12), string.sub(pixels[i], 1, 3), string.sub(pixels[i], 4, 6), string.sub(pixels[i], 7, 9))
  42. end end
  43.  
  44. script.Parent.Render.MouseButton1Down:connect(function ()
  45. if script.Parent.Render.Text == "Render image" then
  46. if tonumber(script.Parent.PixelSize.Text) then
  47. pixelsize = script.Parent.PixelSize.Text
  48. end
  49. currentpixel = {1, 0}
  50. for _, a in pairs(script.Parent:GetChildren()) do
  51. if a.className == "TextLabel" then
  52. a:Remove()
  53. end end
  54. script.Parent.Render.Text = "Time to completion: "..math.ceil(resx * resy * 0.04 / pxnumwait)
  55. getpicture()
  56. script.Parent.Render.Text = "Render image"
  57. end end)
Advertisement
Add Comment
Please, Sign In to add comment