Last active
April 27, 2017 20:27
-
-
Save lychrel/16184015b688bbea51601cbec64487ef to your computer and use it in GitHub Desktop.
icon transformations
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
import numpy as np | |
import sys, os | |
# tab length | |
tab = 4 | |
# create icons from input file | |
with open('fills.txt', 'r') as f: | |
bigstr = f.read()[:-1] | |
rows = filCols = bigstr.split('\n\n') | |
rows = [row.split('\n') for row in rows] | |
bitmap = np.array(rows, dtype=object) | |
up, down = tuple([np.rot90(bitmap, i) for i in [1,3]]) # rotation matrices | |
left = np.fliplr(bitmap) # reflection matrix | |
# write icons to output file | |
string = '' | |
with open('icons.asm', 'w') as f: | |
for label, bmap, index in zip(['CAR_RIGHT', 'CAR_UP', 'CAR_LEFT', 'CAR_DOWN'], | |
[bitmap, up, left, down], range(4)): | |
string += label + ' ' # label next car icon | |
bmapl = bmap.flatten() # don't need array structure anymore | |
pixel_rows = [bmapl[x:x+8] # split into pixel rows (just bc) | |
for x in range(0, len(bmapl),8)] | |
for row in pixel_rows: # write each row of pixels to string | |
for fill in row: | |
string += ' ' * (len(label) + tab) # indent nicely | |
string += (fill + '\n') # actual fill | |
string += '\n' | |
string += '\n' | |
# remove extra spaces after label | |
end_of_label = string.find(label) + len(label) | |
string = string[:end_of_label] + string[end_of_label+len(label)+tab:] | |
# sanity check | |
print(string) | |
f.write(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Icon Transformations ( Try Online! )
because nobody likes copy-pasting!
the online