Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Last active August 29, 2015 14:15
Show Gist options
  • Save NotTheEconomist/09e85a135b2d83019ac9 to your computer and use it in GitHub Desktop.
Save NotTheEconomist/09e85a135b2d83019ac9 to your computer and use it in GitHub Desktop.
#Read Custom Animations
import re
import binascii
anim_1 = (r'fire_0_anim.txt')
#repr of anim_1 " '16,\n17,\n18,\n19,\n20,\n21,\n22,\n23,\n24,\n25,\n26,\n27,\n28' "
with open(anim_1, 'rb') as anim_1_:
anim_1_read = anim_1_.read()
anim_1_hex = binascii.hexlify(anim_1_read).decode()
# .decode() to get as string
print(anim_1_hex)
anim_1_len = len(anim_1_read)
print("fire_0 animation length is %s" % anim_1_len)
anim = re.findall('[0-9a-f]{2}', anim_1_hex)
anim_1_edit = [x for x in anim if x not in ('0d', '0a')]
always_null_byte = itertools.repeat("00")
result = [z for z1_z2 in zip(always_null_byte, anim_1_edit) for z in z1_z2]
print (result)
#this prints
"""
'31362c0d0a31372c0d0a31382c0d0a31392c0d0a32302c0d0a32312c0d0a32322c0d0a32332c0d0a32342c0d0a32352c0d0a32362c0d0a32372c0d0a32382c0d0a32392c0d0a33302c0d0a33312c0d0a302c0d0a312c0d0a322c0d0a332c0d0a342c0d0a352c0d0a362c0d0a372c0d0a382c0d0a392c0d0a31302c0d0a31312c0d0a31322c0d0a31332c0d0a31342c0d0a31352c0d0a'
fire_0 animation length is 150
['00', '31', '00', '36', '00', '2c', '00', '31', '00', '37', '00', '2c', '00', '31', '00', '38', '00', '2c', '00', '31', '00', '39', '00', '2c', '00', ... ]
"""
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment