Created
November 19, 2015 23:55
-
-
Save ColtonPhillips/f78e93dcbc0cef92bb5d to your computer and use it in GitHub Desktop.
This converts a png into puzzlescript object format. It works for sizes that aren't typical for the editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addUnique(l,item): | |
if item not in l: | |
l.append(item) | |
return l | |
from PIL import Image | |
import sys | |
im = Image.open(sys.argv[1]) | |
pix = im.load() | |
#first create the legend | |
# Creates a list containing 5 lists initialized to 0 | |
out_l_l = [[0 for x in range(im.size[0])] for x in range(im.size[1])] | |
col_set = [] | |
for j in range(im.size[0]): | |
for i in range(im.size[1]): | |
r, g, b, a = pix[i,j] | |
curPixel = '#%02x%02x%02x' % (r, g, b) | |
if a != 0: | |
addUnique(col_set, curPixel) | |
line = "" | |
for item in col_set: | |
line += item + " " | |
print line | |
for j in range (im.size[0]): | |
line = "" | |
for i in range (im.size[1]): | |
r,g,b,a = pix[i,j] | |
if (a == 0): | |
line += "." | |
else: | |
curPixel = '#%02x%02x%02x' % (r, g, b) | |
line += str(col_set.index(curPixel)) | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment