Hi I have made a quick python script to turn an square picture to a string of text that can the be parsed by pico8 to make a nice splashscreen.
Pico8 code
function txt_to_pic(txt) local d={ a=10, b=11, c=12, d=13, e=14, f=15 } d['0']=0 d['1']=1 d['2']=2 d['3']=3 d['4']=4 d['5']=5 d['6']=6 d['7']=7 d['8']=8 d['9']=9 local x=0 local y=0 for i=0,#txt do if x>128 then x=0 y+=1 end c=d[sub(txt,i,i)] pset(x,y,c) x+=1 end end |
And here is the python script (just replace "me.jpg" by your image):
import numpy import PIL #%% img = PIL.Image.open("me.jpg") img = img.resize((128,128)) imgarr = numpy.array(img) newimg=numpy.array(img) img.resize((128*10,128*10)) p8colors=[ (0,0,0), (29,43,83), (126,37,83), (0,135,81), (171, 82, 54), (95, 87, 79), (194, 195, 199), (255, 241, 232), (255, 0, 77), (255, 163, 0), (255, 236, 39), (0, 228, 54), (41, 173, 255), (131, 118, 156), (255, 119, 168), (255, 204, 170)] col_to_letter='0123456789ABCDEF' def color_dist(a,b): r1,g1,b1 = a[:3] r2,g2,b2 = b[:3] return int(((r1-r2)**2+(g1-g2)**2+(b1-b2)**2)**(0.5)) def best_col(c): distances=[color_dist(c,i) for i in p8colors] m=min(distances) return distances.index(m) STR = '' for y,line in enumerate(imgarr): for x,c in enumerate(line): newc=best_col(c) STR+=col_to_letter[newc] newimg[y][x]=p8colors[newc] STR+='L' p8image=(STR) PIL.Image.fromarray(newimg).resize((1280,1280)) |
by Lahat


P#69552 2019-11-01 12:34 ( Edited 2019-11-01 12:35)


Hi, @Lahat:
I was checking quickly to see if Pico-8 could import .JPG as their spritesheet and sadly see they do not. Nor do they resize from a larger size. So your code is instrumental in that.
However, if you have the ability to already have your image in .PNG format (or can resize and save as PNG with Freeware IrfanVIEW), then you can skip Python completely with:
import me.png |
And then run this code:
t="" for i=0,8191 do t=t..sub(tostr(peek(i),1),5,6) end printh('pic="'..t..'"',"@clip") |
to convert your picture to a single string variable pasted by pressing CTRL-V.
P#69562 2019-11-01 16:12 ( Edited 2019-11-01 22:40)
[Please log in to post a comment]