Skip to content

Instantly share code, notes, and snippets.

@iamgreaser
Created February 4, 2013 21:11
Show Gist options
  • Save iamgreaser/4709760 to your computer and use it in GitHub Desktop.
Save iamgreaser/4709760 to your computer and use it in GitHub Desktop.
# vxl2tga.py: renders a vxl map isometrically
# by GreaseMonkey, 2013 - public domain
import sys, struct
WIDTH, HEIGHT = 2048, 1024+128
g = [[None for i in xrange(WIDTH)] for j in xrange(HEIGHT)]
def pp(x,y,z,col):
rx = (z-x)*2+1024
ry = x+z+y*2
#print rx,ry,x,y,z
g[ry+0][rx+0] = g[ry+1][rx+0] = col
g[ry+0][rx+1] = g[ry+1][rx+1] = col
fp = open(sys.argv[1],"rb")
for x in xrange(512):
for z in xrange(512):
cl = []
lc = None
while True:
n,s,e,a = struct.unpack("<BBBB", fp.read(4))
rn = n if n != 0 else e-s+1
for i in xrange(len(cl)):
pp(x,a-len(cl)+i,z,cl[i])
cl = []
for i in xrange(s,e+1,1):
lc = fp.read(3)
pp(x,i,z,lc)
fp.read(1)
if n == 0:
break
for i in xrange(e-s+1,n-1,1):
cl.append(fp.read(3))
fp.read(1)
for i in xrange(e+1,64,1):
pp(x,i,z,lc)
fp.close()
fp = open(sys.argv[2],"wb")
fp.write(struct.pack("<BBBHHB",0,0,2,0,0,0))
fp.write(struct.pack("<HHHHBB",0,HEIGHT-1,WIDTH,HEIGHT,32,7+32))
for l in g:
for v in l:
fp.write("\x00\x00\x00\x00" if v == None else v + "\xFF")
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment