Modified from the original work of @neon jewel from their github repo https://github.com/irtsa-dev/greyscript-tools/wiki/Num-to-Sprite
Prompts for a filepath to the data/image file.
Example.png
092207251245168184255255255245168184092207251
092207251245168184255255255245168184092207251
092207251245168184255255255245168184092207251
092207251245168184255255255245168184092207251
092207251245168184255255255245168184092207251
28
Each line should be N chunks of 9 chars each where each chunk is 3 sub-chunks denoting the int R,G, and B values (rgb(255,100,50) => 255100050 note that 50 was padded to 050)
sprite:
//Additional Functions (from bltings)
list.applyFunction = function(func, arg=null)
for i in range(self.len - 1)
if not arg then self[i] = func(self[i]) else self[i] = func(self[i], arg)
end for
return self
end function
list.min = function()
m = self[0]
for i in self
if i < m then m = i
end for
return m
end function
list.max = function()
m = self[0]
for i in self
if i > m then m = i
end for
return m
end function
string.splitN = function(groupsize)
return self.matches("[\w\d]{"+groupsize+"}").values
end function
// sister function
list.mergeN = function(n)
out = []
if n <= 0 or len(self) == 0 then return out
for i in range(0, len(self)-1, n)
temp = []
for j in range(0, n-1)
if i+j < len(self) then
temp.push(str(self[i+j]))
end if
end for
out.push(temp.join(""))
end for
return out
end function
rgbInt2Hex = function(rgbstr)
// "255000255255000255255000255...(len % 9 = 0)"
// => ["255","000", "255", ...]
// => ["FF","00", "FF", ...]
// => ["FF00FF", ...]
// => "FF00FFFF00FFFF00FF..."
rgbIntList = rgbstr.splitN(3)
rgbStrList = rgbIntList.applyFunction(@hex,2)
return rgbStrList.mergeN(3)
end function
hex = function(intstr, len=null)
n = intstr.to_int
if n == 0 then return "0"*len
hexchars = "0123456789ABCDEF"
result = ""
while n > 0
remainder = n % 16
digit = hexchars[remainder]
result = digit + result
n = floor(n / 16)
end while
if len and result.len < len then return "0"*(len-results.len)+result
return result
end function
sprite = function(filepath)
file = get_shell.host_computer.File(filepath)
if not file or not file.has_permission("r") then exit("<color=red>Error: File is inaccessible.</color>")
imageData = file.get_content.split("\n")
imageSize = imageData[-1].to_int
imageData.pop
for i in range(imageData.len-1)
if imageData[i].len %9 != 0 then exit("<color=red> Error: Malformed line: <color=white>"+i+"</color> - each line length should be a factor of 9 (ex. 255000255...)</color>")
end for
imageData.applyFunction(@rgbInt2Hex)
picture = ""
for a in range(0, imageData.len - 1)
for b in range(0, imageData[a].len - 1)
color = imageData[a][b]
if color == "000000" and zeroIsInvisible then color = "0b0b0c"
picture = picture + "<pos=" + floor(b * imageSize * 0.6) + "px><size=" + imageSize + "><sprite=0 color=#" + color + ">"
end for
picture = picture + "<voffset=-" + floor((a + 1) * imageSize * 1.2) + "px>"
end for
return picture
end function
print(sprite(user_input("Enter image filepath: ")))