Last active
April 19, 2017 22:04
-
-
Save rakiru/7515978 to your computer and use it in GitHub Desktop.
Render an isometric overview of a VXL (AoS 0.x) map to a PNG.
Improved version available here: https://gist.github.com/learn-more/7592999
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vxl2png.py: renders a vxl map isometrically | |
# by rakiru, 2013 - public domain | |
# Based on vxl2tga.py by GreaseMonkey, 2013 - public domain | |
# https://gist.github.com/iamgreaser/4709760 | |
import sys, struct | |
import Image | |
if len(sys.argv) != 3: | |
print "Usage: %s mapfile.vxl output.png" % sys.argv[0] | |
exit(0) | |
WIDTH, HEIGHT = 2048, 1024+128 | |
img = Image.new("RGBA", (WIDTH, HEIGHT)) | |
def pp(x,y,z,col): | |
rx = (z-x)*2+(WIDTH/2) | |
ry = x+z+y*2 | |
#print rx,ry,x,y,z | |
try: | |
for i in xrange(2): | |
for j in xrange(2): | |
img.im.putpixel((rx+i, ry+j), col) | |
except Exception as e: | |
print rx, ry | |
raise e | |
def get_colour(fp): | |
b = struct.unpack('B', fp.read(1))[0] | |
g = struct.unpack('B', fp.read(1))[0] | |
r = struct.unpack('B', fp.read(1))[0] | |
return (r, g, b) | |
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 = get_colour(fp) | |
pp(x,i,z,lc) | |
fp.read(1) | |
if n == 0: | |
break | |
for i in xrange(e-s+1,n-1,1): | |
cl.append(get_colour(fp)) | |
fp.read(1) | |
for i in xrange(e+1,64,1): | |
pp(x,i,z,lc) | |
fp.close() | |
img.save(sys.argv[2], "PNG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment