mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-06-14 15:29:27 +00:00
python 2->3 for tools
This commit is contained in:
parent
6e50cbb20e
commit
149ee4a2eb
|
@ -10,7 +10,7 @@ for root, dirs, files in os.walk("./presets"):
|
||||||
with open(path,'r') as f:
|
with open(path,'r') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
if data[0] != '\n':
|
if data[0] != '\n':
|
||||||
print(path,'no initial newline')
|
print((path,'no initial newline'))
|
||||||
except:
|
except:
|
||||||
print(path,sys.exc_info()[0])
|
print((path,sys.exc_info()[0]))
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,4 @@ for n in range(1,MAXBITS):
|
||||||
seqindex = seq.index(x)
|
seqindex = seq.index(x)
|
||||||
seqlen = len(seq) - seqindex
|
seqlen = len(seq) - seqindex
|
||||||
if seqlen>1:
|
if seqlen>1:
|
||||||
print(seqlen, "#(%d,%d'%s,%d)" % (n,n,bin(i)[1:],invert), seqindex)
|
print((seqlen, "#(%d,%d'%s,%d)" % (n,n,bin(i)[1:],invert), seqindex))
|
||||||
|
|
|
@ -71,7 +71,7 @@ def find_common_substrings(s):
|
||||||
|
|
||||||
def get_best_substring(ss):
|
def get_best_substring(ss):
|
||||||
best = (0,0,0)
|
best = (0,0,0)
|
||||||
for k,v in ss.items():
|
for k,v in list(ss.items()):
|
||||||
if v[0] > best[2]:
|
if v[0] > best[2]:
|
||||||
best = (k,v[1],v[0])
|
best = (k,v[1],v[0])
|
||||||
return best
|
return best
|
||||||
|
@ -88,7 +88,7 @@ def replace_substrings(s, bss):
|
||||||
i,l,n = bss
|
i,l,n = bss
|
||||||
count = (n+1)/(l-1)
|
count = (n+1)/(l-1)
|
||||||
match = s[i:i+l]
|
match = s[i:i+l]
|
||||||
print i,l,n,count,repr(match)
|
print((i,l,n,count,repr(match)))
|
||||||
r = s[0:i]
|
r = s[0:i]
|
||||||
while i<len(s):
|
while i<len(s):
|
||||||
r += chr(g_code)
|
r += chr(g_code)
|
||||||
|
@ -99,7 +99,7 @@ def replace_substrings(s, bss):
|
||||||
i = p
|
i = p
|
||||||
g_subs.append(match + chr(0xff))
|
g_subs.append(match + chr(0xff))
|
||||||
g_code += 1
|
g_code += 1
|
||||||
print len(s), len(r)+n+l
|
print((len(s), len(r)+n+l))
|
||||||
assert len(s) == len(r)+n+l
|
assert len(s) == len(r)+n+l
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -111,10 +111,10 @@ def channels_for_track(track):
|
||||||
return list(channels)
|
return list(channels)
|
||||||
|
|
||||||
if not args.midichannels:
|
if not args.midichannels:
|
||||||
print mid
|
print(mid)
|
||||||
print mid.length, 'seconds'
|
print((mid.length, 'seconds'))
|
||||||
for i, track in enumerate(mid.tracks):
|
for i, track in enumerate(mid.tracks):
|
||||||
print('Track {}: {} ({}) {}'.format(i, track.name, len(track), channels_for_track(track)))
|
print(('Track {}: {} ({}) {}'.format(i, track.name, len(track), channels_for_track(track))))
|
||||||
#for msg in track:
|
#for msg in track:
|
||||||
# print(msg)
|
# print(msg)
|
||||||
else:
|
else:
|
||||||
|
@ -123,9 +123,9 @@ else:
|
||||||
nnotes = 0
|
nnotes = 0
|
||||||
nvoices = 0
|
nvoices = 0
|
||||||
curchans = 0
|
curchans = 0
|
||||||
channels = [int(x) for x in string.split(args.midichannels, ',')]
|
channels = [int(x) for x in args.midichannels.split(',')]
|
||||||
print
|
print ('')
|
||||||
print "// %s %s" % (mid, channels)
|
print(("// %s %s" % (mid, channels)))
|
||||||
output = []
|
output = []
|
||||||
for msg in mid:
|
for msg in mid:
|
||||||
gtime += msg.time * tempo
|
gtime += msg.time * tempo
|
||||||
|
@ -150,22 +150,22 @@ else:
|
||||||
curchans |= 1<<msg.channel
|
curchans |= 1<<msg.channel
|
||||||
output.append(0xff)
|
output.append(0xff)
|
||||||
if coutput:
|
if coutput:
|
||||||
print string.join([hex2(x) for x in output], ',')
|
print((','.join([hex2(x) for x in output])))
|
||||||
else:
|
else:
|
||||||
bighex = string.join([hex1(x) for x in output], '')
|
bighex = ''.join([hex1(x) for x in output])
|
||||||
for i in range(0,len(bighex)+32,32):
|
for i in range(0,len(bighex)+32,32):
|
||||||
print '\thex', bighex[i:i+32]
|
print(('\thex', bighex[i:i+32]))
|
||||||
if compress:
|
if compress:
|
||||||
# replace common substrings
|
# replace common substrings
|
||||||
bout = ''.join(chr(i) for i in output)
|
bout = ''.join(chr(i) for i in output)
|
||||||
for iter in range(0,32):
|
for iter in range(0,32):
|
||||||
ss = find_common_substrings(bout)
|
ss = find_common_substrings(bout)
|
||||||
bss = get_best_substring(ss)
|
bss = get_best_substring(ss)
|
||||||
print bss
|
print(bss)
|
||||||
if bss[1] == 0:
|
if bss[1] == 0:
|
||||||
break
|
break
|
||||||
bout = replace_substrings(bout, bss)
|
bout = replace_substrings(bout, bss)
|
||||||
print repr(bout)
|
print((repr(bout)))
|
||||||
# build substring table
|
# build substring table
|
||||||
ofs = (len(g_subs)+1)*2
|
ofs = (len(g_subs)+1)*2
|
||||||
zout = offset2str(ofs)
|
zout = offset2str(ofs)
|
||||||
|
@ -178,5 +178,5 @@ else:
|
||||||
for ss in g_subs:
|
for ss in g_subs:
|
||||||
zout += ss
|
zout += ss
|
||||||
# print output
|
# print output
|
||||||
print string.join([hex2(ord(x)) for x in zout], ',')
|
print((','.join([hex2(ord(x)) for x in zout])))
|
||||||
print "// compressed %d -> %d bytes" % (len(output), len(zout))
|
print(("// compressed %d -> %d bytes" % (len(output), len(zout))))
|
||||||
|
|
|
@ -35,14 +35,14 @@ for a440 in range(4300,4500):
|
||||||
results.sort()
|
results.sort()
|
||||||
best_error, best_a440 = results[0]
|
best_error, best_a440 = results[0]
|
||||||
best_a440 /= 10.0
|
best_a440 /= 10.0
|
||||||
print '//', args
|
print('//', args)
|
||||||
print '//', best_a440, best_error, test_notes
|
print('//', best_a440, best_error, test_notes)
|
||||||
|
|
||||||
print "const int note_table[%d] = {" % final_notes
|
print("const int note_table[%d] = {" % final_notes)
|
||||||
for note in range(0,final_notes):
|
for note in range(0,final_notes):
|
||||||
notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0);
|
notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0);
|
||||||
period = int(round(basehz / notehz)) - bias
|
period = int(round(basehz / notehz)) - bias
|
||||||
while period > maxval:
|
while period > maxval:
|
||||||
period /= 2
|
period /= 2
|
||||||
print '%d,' % period,
|
print('%d,' % period, end='')
|
||||||
print "};"
|
print("};")
|
||||||
|
|
|
@ -45,21 +45,18 @@ for a440 in range(4200,4600):
|
||||||
if period3 < s or period3 > 32*s:
|
if period3 < s or period3 > 32*s:
|
||||||
tonehz3 = -10000
|
tonehz3 = -10000
|
||||||
error += min(abs(notehz-tonehz), abs(notehz-tonehz2), abs(notehz-tonehz3))
|
error += min(abs(notehz-tonehz), abs(notehz-tonehz2), abs(notehz-tonehz3))
|
||||||
#print a440,note,notehz,notehz-tonehz,period
|
|
||||||
#if a440 == 4405:
|
|
||||||
# print '%d,%f,%d' % (note,tonehz-notehz,period)
|
|
||||||
results.append((error, a440))
|
results.append((error, a440))
|
||||||
|
|
||||||
results.sort()
|
results.sort()
|
||||||
best_error, best_a440 = results[0]
|
best_error, best_a440 = results[0]
|
||||||
best_a440 /= 10.0
|
best_a440 /= 10.0
|
||||||
print '//', best_a440, best_error, test_notes
|
print('//', best_a440, best_error, test_notes)
|
||||||
|
|
||||||
periods = []
|
periods = []
|
||||||
tones = []
|
tones = []
|
||||||
bits = []
|
bits = []
|
||||||
|
|
||||||
print "const int note_table[%d] = {" % final_notes
|
print("const int note_table[%d] = {" % final_notes)
|
||||||
for note in range(0,final_notes):
|
for note in range(0,final_notes):
|
||||||
notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0);
|
notehz = best_a440 * math.pow(2.0, (note - 49) / 12.0);
|
||||||
bestperiod = 255
|
bestperiod = 255
|
||||||
|
@ -75,8 +72,8 @@ for note in range(0,final_notes):
|
||||||
bestperiod = period
|
bestperiod = period
|
||||||
besthz = hz
|
besthz = hz
|
||||||
|
|
||||||
#print '%d,' % period,
|
#print(note, besthz, bestperiod, notehz)
|
||||||
print note, besthz, bestperiod, notehz
|
print('%d,' % period, end='')
|
||||||
periods.append(bestperiod / s - 1)
|
periods.append(bestperiod / s - 1)
|
||||||
bits.append(bittable[bestperiod & (s-1)])
|
bits.append(bittable[bestperiod & (s-1)])
|
||||||
if besthz==basehz:
|
if besthz==basehz:
|
||||||
|
@ -87,8 +84,8 @@ for note in range(0,final_notes):
|
||||||
tones.append(6)
|
tones.append(6)
|
||||||
else:
|
else:
|
||||||
tones.append(0)
|
tones.append(0)
|
||||||
print "};"
|
print("};")
|
||||||
|
|
||||||
print periods
|
print(periods)
|
||||||
print bits
|
print(bits)
|
||||||
print tones
|
print(tones)
|
||||||
|
|
|
@ -23,15 +23,15 @@ def out(i, pix, lb, hb, reverse=0, shift=0):
|
||||||
with open(sys.argv[1],'rb') as f:
|
with open(sys.argv[1],'rb') as f:
|
||||||
# read PBM header
|
# read PBM header
|
||||||
header = f.readline().strip()
|
header = f.readline().strip()
|
||||||
assert(header == 'P4')
|
assert(header == b'P4')
|
||||||
dims = f.readline().strip()
|
dims = f.readline().strip()
|
||||||
if dims[0] == '#':
|
if dims[0:1] == b'#':
|
||||||
dims = f.readline().strip()
|
dims = f.readline().strip()
|
||||||
width,height = map(int, dims.split())
|
width,height = list(map(int, dims.split()))
|
||||||
assert(width==48)
|
assert(width==48)
|
||||||
# read bitmap rows
|
# read bitmap rows
|
||||||
for y in range(0,height):
|
for y in range(0,height):
|
||||||
row = bytes(f.read(6) + '\0\0') # pad to 8 bytes
|
row = bytes(f.read(6) + b'\0\0') # pad to 8 bytes
|
||||||
# convert to 64-bit integer
|
# convert to 64-bit integer
|
||||||
pix = struct.unpack('<q',row)[0]
|
pix = struct.unpack('<q',row)[0]
|
||||||
#print '%010lx' % pix
|
#print '%010lx' % pix
|
||||||
|
@ -45,14 +45,14 @@ with open(sys.argv[1],'rb') as f:
|
||||||
|
|
||||||
# output bitmap tables
|
# output bitmap tables
|
||||||
for c in range(0,6):
|
for c in range(0,6):
|
||||||
print "\talign $100"
|
print("\talign $100")
|
||||||
print "Bitmap%d" % c
|
print(("Bitmap%d" % c))
|
||||||
print "\thex 00"
|
print("\thex 00")
|
||||||
s = '\thex '
|
s = '\thex '
|
||||||
for i in range(0,height):
|
for i in range(0,height):
|
||||||
s += '%02x' % output[c][height-i-1]
|
s += '%02x' % output[c][height-i-1]
|
||||||
if i % 16 == 15:
|
if i % 16 == 15:
|
||||||
print s
|
print(s)
|
||||||
s = '\thex '
|
s = '\thex '
|
||||||
if len(s)>5:
|
if len(s)>5:
|
||||||
print s
|
print(s)
|
||||||
|
|
|
@ -23,22 +23,22 @@ def out(i, pix, lb, hb, reverse=0, shift=0):
|
||||||
with open(sys.argv[1],'rb') as f:
|
with open(sys.argv[1],'rb') as f:
|
||||||
# read PBM header
|
# read PBM header
|
||||||
header = f.readline().strip()
|
header = f.readline().strip()
|
||||||
assert(header == 'P4')
|
assert(header == b'P4')
|
||||||
dims = f.readline().strip()
|
dims = f.readline().strip()
|
||||||
if dims[0] == '#':
|
if dims[0:1] == b'#':
|
||||||
dims = f.readline().strip()
|
dims = f.readline().strip()
|
||||||
width,height = map(int, dims.split())
|
print(dims)
|
||||||
|
width,height = list(map(int, dims.split()))
|
||||||
assert(width==40)
|
assert(width==40)
|
||||||
# read bitmap rows
|
# read bitmap rows
|
||||||
for y in range(0,height):
|
for y in range(0,height):
|
||||||
row = bytes(f.read(5) + '\0\0\0') # pad to 8 bytes
|
row = bytes(f.read(5) + b'\0\0\0') # pad to 8 bytes
|
||||||
# convert bytes from MSB first to LSB first
|
# convert bytes from MSB first to LSB first
|
||||||
row2 = ''
|
row2 = []
|
||||||
for i in range(0,8):
|
for i in range(0,8):
|
||||||
row2 += chr(rev(ord(row[i])))
|
row2.append(rev(row[i]))
|
||||||
# convert to 64-bit integer
|
# convert to 64-bit integer
|
||||||
pix = struct.unpack('<q',row2)[0]
|
pix = struct.unpack('<q',bytes(row2))[0]
|
||||||
#print '%010lx' % pix
|
|
||||||
# generate playfield bytes
|
# generate playfield bytes
|
||||||
out(0, pix, 0, 4, 0, 4)
|
out(0, pix, 0, 4, 0, 4)
|
||||||
out(1, pix, 4, 12, 1)
|
out(1, pix, 4, 12, 1)
|
||||||
|
@ -49,14 +49,12 @@ with open(sys.argv[1],'rb') as f:
|
||||||
|
|
||||||
# output bitmap tables
|
# output bitmap tables
|
||||||
for c in range(0,6):
|
for c in range(0,6):
|
||||||
#print "\talign $100"
|
print(("PFBitmap%d" % c))
|
||||||
print "PFBitmap%d" % c
|
|
||||||
#print "\thex 00"
|
|
||||||
s = '\thex '
|
s = '\thex '
|
||||||
for i in range(0,height):
|
for i in range(0,height):
|
||||||
s += '%02x' % output[c][height-i-1]
|
s += '%02x' % output[c][height-i-1]
|
||||||
if i % 16 == 15:
|
if i % 16 == 15:
|
||||||
print s
|
print(s)
|
||||||
s = '\thex '
|
s = '\thex '
|
||||||
if len(s)>5:
|
if len(s)>5:
|
||||||
print s
|
print(s)
|
||||||
|
|
|
@ -13,7 +13,6 @@ with open(sys.argv[1],'r') as f:
|
||||||
for l in lines:
|
for l in lines:
|
||||||
l = l.strip()
|
l = l.strip()
|
||||||
toks = l.split()
|
toks = l.split()
|
||||||
#print l,toks
|
|
||||||
if toks[0] == 'ENCODING':
|
if toks[0] == 'ENCODING':
|
||||||
chord = int(toks[1])
|
chord = int(toks[1])
|
||||||
elif toks[0] == 'BITMAP':
|
elif toks[0] == 'BITMAP':
|
||||||
|
@ -26,7 +25,7 @@ with open(sys.argv[1],'r') as f:
|
||||||
bytes.insert(0,0)
|
bytes.insert(0,0)
|
||||||
assert(len(bytes) == height)
|
assert(len(bytes) == height)
|
||||||
bytes.reverse()
|
bytes.reverse()
|
||||||
print chord,bytes
|
print((chord,bytes))
|
||||||
chars[chord] = bytes
|
chars[chord] = bytes
|
||||||
elif inbitmap and len(toks) == 1:
|
elif inbitmap and len(toks) == 1:
|
||||||
byte = int(toks[0],16)
|
byte = int(toks[0],16)
|
||||||
|
@ -63,10 +62,10 @@ def tohex2(v):
|
||||||
def tobin(v):
|
def tobin(v):
|
||||||
return "bitarray[0][0]=3'b{0:3b};\n".format(v)
|
return "bitarray[0][0]=3'b{0:3b};\n".format(v)
|
||||||
|
|
||||||
print '\thex ' + string.join(map(tohex,output),'')
|
print(('\thex ' + ''.join(map(tohex,output))))
|
||||||
print string.join(map(tohex2,output),',')
|
print((''.join(map(tohex2,output))))
|
||||||
print '\thex ' + string.join(map(tohex,outputlo),'')
|
print(('\thex ' + ''.join(map(tohex,outputlo))))
|
||||||
print '\thex ' + string.join(map(tohex,outputhi),'')
|
print(('\thex ' + ''.join(map(tohex,outputhi))))
|
||||||
print string.join(map(tobin,output),'')
|
print((''.join(map(tobin,output))))
|
||||||
|
|
||||||
print len(output),len(outputlo),len(outputhi)
|
print((len(output),len(outputlo),len(outputhi)))
|
||||||
|
|
|
@ -50,16 +50,16 @@ with open(args.bdffile,'r') as f:
|
||||||
if bytes[y] & (0x40 >> x):
|
if bytes[y] & (0x40 >> x):
|
||||||
b |= 0x0f
|
b |= 0x0f
|
||||||
output.append(b)
|
output.append(b)
|
||||||
print 'const char CH_%d[] = { %s };' % ( chord, string.join([tohex2(x) for x in output], ',') )
|
print('const char CH_%d[] = { %s };' % ( chord, string.join([tohex2(x) for x in output], ',') ))
|
||||||
chars[chord] = 'CH_%d' % chord
|
chars[chord] = 'CH_%d' % chord
|
||||||
elif inbitmap and len(toks) == 1:
|
elif inbitmap and len(toks) == 1:
|
||||||
byte = int(toks[0],16)
|
byte = int(toks[0],16)
|
||||||
bytes.append(byte)
|
bytes.append(byte)
|
||||||
|
|
||||||
print 'const char* const FONT_TABLE[%d] = {' % (hichar-lochar+1),
|
print('const char* const FONT_TABLE[%d] = {' % (hichar-lochar+1), end=' ')
|
||||||
for ch in range(lochar, hichar+1):
|
for ch in range(lochar, hichar+1):
|
||||||
if chars.get(ch):
|
if chars.get(ch):
|
||||||
print '%s,' % chars[ch],
|
print('%s,' % chars[ch], end=' ')
|
||||||
else:
|
else:
|
||||||
print '0,',
|
print('0,', end=' ')
|
||||||
print "};"
|
print("};")
|
||||||
|
|
|
@ -99,20 +99,20 @@ def tohexv(v):
|
||||||
|
|
||||||
for arr in [output]:
|
for arr in [output]:
|
||||||
if args.asmhex:
|
if args.asmhex:
|
||||||
print '\thex ' + string.join(map(tohex,arr),'')
|
print('\thex ' + string.join(list(map(tohex,arr)),''))
|
||||||
if args.asmdb:
|
if args.asmdb:
|
||||||
for i in range(0,len(output),height):
|
for i in range(0,len(output),height):
|
||||||
print '.DB', string.join(map(tohex2,arr[i:i+height]),','), ';%d'%(i/height+lochar)
|
print('.DB', string.join(list(map(tohex2,arr[i:i+height])),','), ';%d'%(i/height+lochar))
|
||||||
if args.carray:
|
if args.carray:
|
||||||
print "static char FONT[%d][%d] = {" % (hichar-lochar+1, height)
|
print("static char FONT[%d][%d] = {" % (hichar-lochar+1, height))
|
||||||
for i in range(0,len(output),height):
|
for i in range(0,len(output),height):
|
||||||
print '{', string.join(map(tohex2,arr[i:i+height]),','), '},',
|
print('{', string.join(list(map(tohex2,arr[i:i+height])),','), '},', end=' ')
|
||||||
print
|
print()
|
||||||
print "};"
|
print("};")
|
||||||
if args.flatcarray:
|
if args.flatcarray:
|
||||||
print "static char FONT[%d] = {" % ((hichar-lochar+1) * height)
|
print("static char FONT[%d] = {" % ((hichar-lochar+1) * height))
|
||||||
print string.join(map(tohex2,arr),',')
|
print(string.join(list(map(tohex2,arr)),','))
|
||||||
print "}";
|
print("}");
|
||||||
if args.verilog:
|
if args.verilog:
|
||||||
j = 0
|
j = 0
|
||||||
for i in range(0,len(output),height):
|
for i in range(0,len(output),height):
|
||||||
|
@ -121,5 +121,5 @@ for arr in [output]:
|
||||||
#print "rom["+str(j)+"] = 32'h" + string.join(map(tohex,arr[i+height/2:i+height]),'') + ";"
|
#print "rom["+str(j)+"] = 32'h" + string.join(map(tohex,arr[i+height/2:i+height]),'') + ";"
|
||||||
#j += 1
|
#j += 1
|
||||||
#print "rom["+str(j)+"] = 64'h" + string.join(map(tohex,arr[i:i+height]),'') + ";"
|
#print "rom["+str(j)+"] = 64'h" + string.join(map(tohex,arr[i:i+height]),'') + ";"
|
||||||
print string.join(map(tohexv,arr[i:i+height]),',') + ", //%d" % (i/height)
|
print(string.join(list(map(tohexv,arr[i:i+height])),',') + ", //%d" % (i/height))
|
||||||
j += 1
|
j += 1
|
||||||
|
|
|
@ -27,11 +27,11 @@ with open(sys.argv[1],'rb') as f:
|
||||||
width,height = map(int, dims.split())
|
width,height = map(int, dims.split())
|
||||||
wbytes = (width+7)/8
|
wbytes = (width+7)/8
|
||||||
data = f.read()
|
data = f.read()
|
||||||
print "{%d,%d," % (wbytes,height),
|
print("{%d,%d," % (wbytes,height), end='')
|
||||||
for i in range(0,len(data)):
|
for i in range(0,len(data)):
|
||||||
if i>0:
|
if i>0:
|
||||||
sys.stdout.write(",")
|
sys.stdout.write(",")
|
||||||
ofs = i+wbytes-(i%wbytes)*2-1
|
ofs = i+wbytes-(i%wbytes)*2-1
|
||||||
sys.stdout.write( "0x%02x" % ord(data[ofs]) )
|
sys.stdout.write( "0x%02x" % ord(data[ofs]) )
|
||||||
print "}"
|
print("}")
|
||||||
|
|
||||||
|
|
|
@ -19,21 +19,21 @@ with open(sys.argv[1],'rb') as f:
|
||||||
assert data[3] == 8
|
assert data[3] == 8
|
||||||
|
|
||||||
# palette
|
# palette
|
||||||
print "byte palette[16] = {",
|
print("byte palette[16] = {", end='')
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
r = data[16+i*3]
|
r = data[16+i*3]
|
||||||
g = data[17+i*3]
|
g = data[17+i*3]
|
||||||
b = data[18+i*3]
|
b = data[18+i*3]
|
||||||
entry = (r>>5) | ((g>>2)&0x38) | (b&0xc0)
|
entry = (r>>5) | ((g>>2)&0x38) | (b&0xc0)
|
||||||
print '%s,' % (tohex2(entry)),
|
print('%s,' % (tohex2(entry)), end='')
|
||||||
print "}"
|
print("}")
|
||||||
|
|
||||||
# image data
|
# image data
|
||||||
width = (data[9] << 8) + data[8] + 1
|
width = (data[9] << 8) + data[8] + 1
|
||||||
height = (data[11] << 8) + data[10] + 1
|
height = (data[11] << 8) + data[10] + 1
|
||||||
rowlen = (data[0x43] << 8) + data[0x42]
|
rowlen = (data[0x43] << 8) + data[0x42]
|
||||||
print "const byte sprite[] = {"
|
print("const byte sprite[] = {")
|
||||||
print "%d,%d," % ((width+1)/2,height)
|
print("%d,%d," % ((width+1)/2,height))
|
||||||
for y in range(0,height):
|
for y in range(0,height):
|
||||||
ofs = 0x80 + y*rowlen
|
ofs = 0x80 + y*rowlen
|
||||||
output = []
|
output = []
|
||||||
|
@ -41,6 +41,6 @@ with open(sys.argv[1],'rb') as f:
|
||||||
b = (tocolor(data[ofs]) << 4) + tocolor(data[ofs+1])
|
b = (tocolor(data[ofs]) << 4) + tocolor(data[ofs+1])
|
||||||
output.append(b)
|
output.append(b)
|
||||||
ofs += 2
|
ofs += 2
|
||||||
print string.join(map(tohex2,output),',') + ','
|
print(','.join(map(tohex2,output)) + ',')
|
||||||
print "}"
|
print("}")
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,6 @@ n = 4
|
||||||
m = 7
|
m = 7
|
||||||
|
|
||||||
for i in range(0,n*4):
|
for i in range(0,n*4):
|
||||||
print '%d,' % int(round(math.sin(i*math.pi/2/n)*m)),
|
print('%d,' % int(round(math.sin(i*math.pi/2/n)*m)), end='')
|
||||||
if i % 16 == 15:
|
if i % 16 == 15:
|
||||||
print
|
print('')
|
||||||
|
|
|
@ -14,7 +14,7 @@ def textToColor(name,opacity):
|
||||||
return None
|
return None
|
||||||
color = int(name[1:],16) << 8
|
color = int(name[1:],16) << 8
|
||||||
if opacity:
|
if opacity:
|
||||||
print 'opacity',opacity
|
print(('opacity',opacity))
|
||||||
return color
|
return color
|
||||||
|
|
||||||
svg_file = sys.argv[1]
|
svg_file = sys.argv[1]
|
||||||
|
@ -24,7 +24,7 @@ groups = doc.getElementsByTagName('g')
|
||||||
for grp in groups:
|
for grp in groups:
|
||||||
groupID = grp.getAttribute('id')
|
groupID = grp.getAttribute('id')
|
||||||
paths = grp.getElementsByTagName('path')
|
paths = grp.getElementsByTagName('path')
|
||||||
print groupID,paths
|
print((groupID,paths))
|
||||||
if len(paths):
|
if len(paths):
|
||||||
for path in paths:
|
for path in paths:
|
||||||
shape = {}
|
shape = {}
|
||||||
|
@ -36,7 +36,7 @@ for grp in groups:
|
||||||
nvarr = s.split(':', 2)
|
nvarr = s.split(':', 2)
|
||||||
if len(nvarr) == 2:
|
if len(nvarr) == 2:
|
||||||
styleAttrs[nvarr[0]] = nvarr[1]
|
styleAttrs[nvarr[0]] = nvarr[1]
|
||||||
print path,d,styleAttrs
|
print((path,d,styleAttrs))
|
||||||
shape['pts'] = []
|
shape['pts'] = []
|
||||||
shape['currentColor'] = textToColor(styleAttrs.get("stroke"), styleAttrs.get("stroke-opacity"))
|
shape['currentColor'] = textToColor(styleAttrs.get("stroke"), styleAttrs.get("stroke-opacity"))
|
||||||
shape['currentWidth'] = textToFloat(styleAttrs.get("strokeWidth"))
|
shape['currentWidth'] = textToFloat(styleAttrs.get("strokeWidth"))
|
||||||
|
@ -47,7 +47,7 @@ for grp in groups:
|
||||||
i0 = 0
|
i0 = 0
|
||||||
start = True
|
start = True
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
print cmd
|
print(cmd)
|
||||||
ch = cmd[0]
|
ch = cmd[0]
|
||||||
if ch == 'm' or ch == 'l':
|
if ch == 'm' or ch == 'l':
|
||||||
start = True
|
start = True
|
||||||
|
@ -58,7 +58,7 @@ for grp in groups:
|
||||||
skip = True
|
skip = True
|
||||||
else:
|
else:
|
||||||
xy = cmd.split(',')
|
xy = cmd.split(',')
|
||||||
print xy
|
print(xy)
|
||||||
x += float(xy[0])
|
x += float(xy[0])
|
||||||
y -= float(xy[1])
|
y -= float(xy[1])
|
||||||
if start or hidden:
|
if start or hidden:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user