Merge pull request #5 from twolfson/dev/add.str.to.sprite.support

Added multi-line ASCII to sprite support
This commit is contained in:
Eric Romano
2013-05-26 14:46:39 -07:00

View File

@ -76,6 +76,42 @@ hireme=[
[2,0,2,0,2,0,2,0,0,0,2,0,0,0,0,2,0,2,0,2,0,2,0,0], [2,0,2,0,2,0,2,0,0,0,2,0,0,0,0,2,0,2,0,2,0,2,0,0],
[1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,1]] [1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,1]]
ascii_to_number = {
'_': 0,
'_': 1,
'~': 2,
'=': 3,
'*': 4
}
def str_to_sprite(content):
# Break out lines and filter any excess
lines = content.split('\n')
def is_empty_line(line):
return len(line) != 0
lines = filter(is_empty_line, lines)
# Break up lines into each character
split_lines = map(list, lines)
# Replace each character with its numeric equivalent
for line in split_lines:
for index, char in enumerate(line):
line[index] = ascii_to_number.get(char, 0)
# Return the formatted str
return split_lines
oneup_str = str_to_sprite("""
*******
*=~~-~~=*
*~~---~~*
*=*****=*
**-*-*-**
*-----*
*****
""")
images={ images={
'kitty':kitty, 'kitty':kitty,
'oneup':oneup, 'oneup':oneup,
@ -84,7 +120,8 @@ images={
'octocat':octocat, 'octocat':octocat,
'octocat2':octocat2, 'octocat2':octocat2,
'hello':hello, 'hello':hello,
'hireme':hireme 'hireme':hireme,
'oneup_str':oneup_str
} }
def load_images(imgNames): def load_images(imgNames):