Skip to content

Instantly share code, notes, and snippets.

@lychrel
Last active April 27, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lychrel/16184015b688bbea51601cbec64487ef to your computer and use it in GitHub Desktop.
Save lychrel/16184015b688bbea51601cbec64487ef to your computer and use it in GitHub Desktop.
icon transformations
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)
@lychrel
Copy link
Author

lychrel commented Apr 27, 2017

Icon Transformations ( Try Online! )

because nobody likes copy-pasting!

  • input: fills.txt (car icon without label or origins)
  • output: icon.asm (all icons as labeled sets of .FILLs)
    the online

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment