Hey,
Wanted to share some basic code I wrote, I wanted to create a way to display the album cover of the song someone is currently listening to in a plugin using parts as pixels and a viewport frame. I know I could do something like Local File Importer but I want to stick with a pixel(y) or blocky like look.
I use Python to convert images into Lua files. Then using a module create parts that act as pixels to generate something that closely resembles the image.
Python Script:
import os
from PIL import Image
factor = 6.4 #Rate of change to resolution 1: Original resolution. ie: 640x640 - 6.4 - 100x100
rate = 100 #Rate that parts are created at
for filename in os.listdir("input"):
image = Image.open(os.path.join("input", filename))
image = image.resize((int(image.size[0]/factor), int(image.size[1]/factor)))
pixels = image.load()
with open(f"{os.path.join('output', filename)}.lua", 'w') as f:
bits = []
for y in range(image.size[0]):
for x in range(image.size[1]):
p = pixels[x, y]
p = ("{:03d}".format(p[0]), "{:03d}".format(p[1]), "{:03d}".format(p[2]))
bits.append(''.join(map(str, p)))
f.write("require(script.Parent.Parent):Draw("+str(rate)+", Vector3.new(0,0,0), {"+str(image.size[0])+","+str(image.size[1])+"}, '"+''.join(bits)+"')")
f.close()
print("Done!")
Lua Script:
--Netpex 2023
local ImageGenerator = {}
function ImageGenerator:Draw(rate, origin, size, image)
local pos = origin
local activePixel
local color = {}
local bit = ""
for p = 1, (size[1] * size[2])*9, 1 do
bit = bit..tostring(string.sub(image, p, p))
if p/3 % 1 == 0 then
table.insert(color, tonumber(bit))
bit = ""
end
if p/9 % 1 == 0 then
activePixel = Instance.new("Part", workspace)
activePixel.TopSurface = Enum.SurfaceType.Smooth
activePixel.Size = Vector3.new(1, 1, 1)
activePixel.Anchored = true
activePixel.Position = pos
pos -= Vector3.new(1, 0, 0)
activePixel.Color = Color3.fromRGB(color[1], color[2], color[3])
table.clear(color)
bit = ""
end
if p/(rate*9) % 1 == 0 then
wait()
end
if p/(size[1]*9) % 1 == 0 then
pos = origin - Vector3.new(0, 0, p/(size[1]*9))
end
end
end
return ImageGenerator
Image file example:
require(script.Parent.Parent):Draw(100, Vector3.new(0,0,0), {40,40}, '000000000000000000000000000000000000000000000000000000000000000229025025226034025231035026230035027231035023204051051000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000227033027226035026233036027231036027227035026227034025229035025228035026232037030255000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000225034026235036027226035026226035026228035026231036027235036027233036027226035026227035026228035026229034025229034025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000226034025234036027226035026226035026226035026226035026226035026226035026228035026232036027235036027232036027227035026227034025228035026227034027234030030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000231046023225034026230036026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026232036027235036027231036027227035025228034026227035025228033026230036024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000225034024228035026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026229035026233036027235036027230036026227035026227035026228035026230037024240030030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000225034025235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026229035026233036027235036027228035026228034025229035025228035026227036027218036018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000226034026234036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026229036026234036027235036027227035026227035026226035026229034025230035025218036018000000000000000000000000000000000000000000000236036018224034025230036026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026230036026234036027235036027227035026226034026000000000000000000000000000000000000000000000228035026228035026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026232036027227034026000000000000000000000000000000000000000000000225034025235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026231036027226035025000000000000000000000000000000000000000000000225034026233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026226035025227032027000000000000000000000000000000000000226028028225035026229035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026231036027226034026255036036000000000000000000000000000000000000223035027229035026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027227034026000000000000000000000000000000000000000000000226034026235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026234036027224035027000000000000000000000000000000000000000000000226035025233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026232036027235036027232036027228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026227035025221033026000000000000000000000000000000000000231034023225034025229035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026233036027225035026227034024228034026227035026226035026233036027233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026231036027225035025204051000000000000000000000000000000000000000226035025231036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026234036027226034025000000000000000000255000000233036029226034025227035025226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027226035025000000000000000000000000000000000000000000000226034026235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026227035025226035028000000000000000000000000000000000000000000000227035027230036026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026233036027225035026000000000000000000000000000000000000255000000226035026232036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026231036027225035025255063000000000000000000000000000000000000000000000000226035026235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026226035026224038023000000000000000000000000000000000000225039029225035025228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027226035025000000000000000000000000000000000000000000000255000000226034025232036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026232036027225035026170000000000000000000000000000000000000000000225036026232036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026232036027225035026000000000000000000000000000000000000000000000227036027225034026228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027226035026000000000000000000000000000000000000000000000225034025235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026228036026230036027230032024000000000000000000000000000225035025233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026232036027226035025000000000000000000000000000000000000255000000226034025232036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026233036027233036027227034026227034025229035025227034024226035025234036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026226034026227036027000000000000000000000000000000000000229034025225034026228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026228035026232036027235036027230036026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026232036027226034025255000000000000000000000000000000000000000000223034024233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027226035026000000000000000000000000000000000000000000000226035026235036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026231036027227034024000000000000000000000000000000000000191000000226035026232036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026229035026225035025232033022000000000000000000000000000000000000228033026225034026228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026233036027226034025000000000000000000000000000000000000000000000226034026230036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027227035025000000000000000000000000000000000000000000000225035026233036027226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026229035026224034027000000000000000000000000000000000000000000000225035026229035026235036027234036027230036026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026229035026226035026226042028000000000000000000000000000000000000000000000231023023228036026229035025228035026227035026227035026235036027233036027229035026227035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026233036027225034026000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000221034034229034025229034025228035026227035026229036026235036027233036027229035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026235036027225034025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000229038025227034027229035025226034025226035025231036027235036027232036027228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026227035026228035026224034025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000224030030227034027228035026228035026227035026232036027235036027232036027228035026226035026226035026226035026226035026226035026226035026226035026226035026226035026226035026230036026225034025236036018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000221034025229035025228035026227035026227035026233036027235036027231036027228035026226035026226035026226035026226035026226035026226035026234036027225034026000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000255000000225037022228035026227035025227035025227035025234036027235036027231036027227035026226035026226035026235036027225034025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000255063000228033026227036024228034026228035026226035026231036027233036027227035026224035025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000218036036232033027228035026230036025225035026233042021000000000000000000000000000000000000000000000000000000000000000')
Adding the images to Studio:
Once the Lua files are generated, adding them into Roblox Studio is straightforward:
- Importing the Script: Import the generated Lua files into the Roblox Studio module.
- Execution: Run the code within Roblox Studio to visualize the images.
Iām sure this poorly written in many regard, please leave any feedback or ideas you have to improve the concept.
Image to roblox.zip (107.7 KB) (Python)
ImageToRoblox.rbxl (104.8 KB) (Roblox)
Thanks for your time
-Netpex