From 47e4eda4bb87cd9dc20dddf81ca473b523eeb150 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 25 Jun 2011 04:23:21 +0300 Subject: Reorganizing stuff (import from temporary git repo) --- util/genmap.py | 271 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ util/pnoise.py | 102 ++++++++++++++++++++++ 2 files changed, 373 insertions(+) create mode 100755 util/genmap.py create mode 100644 util/pnoise.py (limited to 'util') diff --git a/util/genmap.py b/util/genmap.py new file mode 100755 index 000000000..6b36269d5 --- /dev/null +++ b/util/genmap.py @@ -0,0 +1,271 @@ +#!/usr/bin/python2 + +# This is an example script that generates some valid map data. + +import struct +import random +import os +import sys +import zlib +import array +from pnoise import pnoise + +# Old directory format: +# world/sectors/XXXXZZZZ/YYYY +# XXXX,YYYY,ZZZZ = coordinates in hexadecimal +# fffe = -2 +# ffff = -1 +# 0000 = 0 +# 0001 = 1 +# +# New directory format: +# world/sectors2/XXX/ZZZ/YYYY +# XXX,YYYY,ZZZ = coordinates in hexadecimal +# fffe = -2 +# ffff = -1 +# 0000 = 0 +# 0001 = 1 +# ffe = -2 +# fff = -1 +# 000 = 0 +# 001 = 1 +# +# For more proper file format documentation, refer to mapformat.txt +# For node type documentation, refer to mapnode.h +# NodeMetadata documentation is not complete, refer to nodemeta.cpp +# + +# Seed for generating terrain +SEED = 0 + +# 0=old, 1=new +SECTOR_DIR_FORMAT = 1 + +mapdir = "../world" + +def to4h(i): + s = ""; + s += '{0:1x}'.format((i>>12) & 0x000f) + s += '{0:1x}'.format((i>>8) & 0x000f) + s += '{0:1x}'.format((i>>4) & 0x000f) + s += '{0:1x}'.format((i>>0) & 0x000f) + return s + +def to3h(i): + s = ""; + s += '{0:1x}'.format((i>>8) & 0x000f) + s += '{0:1x}'.format((i>>4) & 0x000f) + s += '{0:1x}'.format((i>>0) & 0x000f) + return s + +def get_sector_dir(px, pz): + global SECTOR_DIR_FORMAT + if SECTOR_DIR_FORMAT == 0: + return "/sectors/"+to4h(px)+to4h(pz) + elif SECTOR_DIR_FORMAT == 1: + return "/sectors2/"+to3h(px)+"/"+to3h(pz) + else: + assert(0) + +def getrand_air_stone(): + i = random.randrange(0,2) + if i==0: + return 0 + return 254 + +# 3-dimensional vector (position) +class v3: + def __init__(self, x=0, y=0, z=0): + self.X = x + self.Y = y + self.Z = z + +class NodeMeta: + def __init__(self, type_id, data): + self.type_id = type_id + self.data = data + +class StaticObject: + def __init__(self): + self.type_id = 0 + self.data = "" + +def ser_u16(i): + return chr((i>>8)&0xff) + chr((i>>0)&0xff) +def ser_u32(i): + return (chr((i>>24)&0xff) + chr((i>>16)&0xff) + + chr((i>>8)&0xff) + chr((i>>0)&0xff)) + +# A 16x16x16 chunk of map +class MapBlock: + def __init__(self): + self.content = array.array('B') + self.param1 = array.array('B') + self.param2 = array.array('B') + for i in range(16*16*16): + # Initialize to air + self.content.append(254) + # Full light on sunlight, none when no sunlight + self.param1.append(15) + # No additional parameters + self.param2.append(0) + + # key = v3 pos + # value = NodeMeta + self.nodemeta = {} + + # key = v3 pos + # value = StaticObject + self.static_objects = {} + + def set_content(self, v3, b): + self.content[v3.Z*16*16+v3.Y*16+v3.X] = b + def set_param1(self, v3, b): + self.param1[v3.Z*16*16+v3.Y*16+v3.X] = b + def set_param2(self, v3, b): + self.param2[v3.Z*16*16+v3.Y*16+v3.X] = b + + # Get data for serialization. Returns a string. + def serialize_data(self): + s = "" + for i in range(16*16*16): + s += chr(self.content[i]) + for i in range(16*16*16): + s += chr(self.param1[i]) + for i in range(16*16*16): + s += chr(self.param2[i]) + return s + + def serialize_nodemeta(self): + s = "" + s += ser_u16(1) + s += ser_u16(len(self.nodemeta)) + for pos, meta in self.nodemeta.items(): + pos_i = pos.Z*16*16 + pos.Y*16 + pos.X + s += ser_u16(pos_i) + s += ser_u16(meta.type_id) + s += ser_u16(len(meta.data)) + s += meta.data + return s + + def serialize_staticobj(self): + s = "" + s += chr(0) + s += ser_u16(len(self.static_objects)) + for pos, obj in self.static_objects.items(): + pos_i = pos.Z*16*16 + pos.Y*16 + pos.X + s += ser_s32(pos.X*1000) + s += ser_s32(pos.Y*1000) + s += ser_s32(pos.Z*1000) + s += ser_u16(obj.type_id) + s += ser_u16(len(obj.data)) + s += obj.data + return s + +def writeblock(mapdir, px,py,pz, block): + + sectordir = mapdir + get_sector_dir(px, pz); + + try: + os.makedirs(sectordir) + except OSError: + pass + + path = sectordir+"/"+to4h(py) + + print("writing block file "+path) + + f = open(sectordir+"/"+to4h(py), "wb") + + if f == None: + return + + # version + version = 17 + f.write(struct.pack('B', version)) + + # flags + # 0x01=is_undg, 0x02=dn_diff, 0x04=lighting_expired + flags = 0 + 0x02 + 0x04 + f.write(struct.pack('B', flags)) + + # data + c_obj = zlib.compressobj() + c_obj.compress(block.serialize_data()) + f.write(struct.pack('BB', 0x78, 0x9c)) # zlib magic number + f.write(c_obj.flush()) + + # node metadata + c_obj = zlib.compressobj() + c_obj.compress(block.serialize_nodemeta()) + f.write(struct.pack('BB', 0x78, 0x9c)) # zlib magic number + f.write(c_obj.flush()) + + # mapblockobject count + f.write(ser_u16(0)) + + # static objects + f.write(block.serialize_staticobj()) + + # timestamp + f.write(ser_u32(0xffffffff)) + + f.close() + +for z0 in range(-1,3): + for x0 in range(-1,3): + for y0 in range(-1,3): + print("generating block "+str(x0)+","+str(y0)+","+str(z0)) + #v3 blockp = v3(x0,y0,z0) + + # Create a MapBlock + block = MapBlock() + + # Generate stuff in it + for z in range(0,16): + for x in range(0,16): + h = 20.0*pnoise((x0*16+x)/100.,(z0*16+z)/100.,SEED+0) + h += 5.0*pnoise((x0*16+x)/25.,(z0*16+z)/25.,SEED+0) + if pnoise((x0*16+x)/25.,(z0*16+z)/25.,SEED+92412) > 0.05: + h += 10 + #print("r="+str(r)) + # This enables comparison by == + h = int(h) + for y in range(0,16): + p = v3(x,y,z) + b = 254 + y1 = y0*16+y + if y1 <= h-3: + b = 0 #stone + elif y1 <= h and y1 <= 0: + b = 8 #mud + elif y1 == h: + b = 1 #grass + elif y1 < h: + b = 8 #mud + elif y1 <= 1: + b = 9 #water + + # Material content + block.set_content(p, b) + + # Place a sign at the center at surface level. + # Placing a sign means placing the sign node and + # adding node metadata to the mapblock. + if x == 8 and z == 8 and y0*16 <= h-1 and (y0+1)*16-1 > h: + p = v3(8,h+1-y0*16,8) + # 14 = Sign + content_type = 14 + block.set_content(p, content_type) + # This places the sign to the bottom of the cube. + # Working values: 0x01, 0x02, 0x04, 0x08, 0x10, 0x20 + block.set_param2(p, 0x08) + # Then add metadata to hold the text of the sign + s = "Hello at sector ("+str(x0)+","+str(z0)+")" + meta = NodeMeta(content_type, ser_u16(len(s))+s) + block.nodemeta[p] = meta + + # Write it on disk + writeblock(mapdir, x0,y0,z0, block) + +#END diff --git a/util/pnoise.py b/util/pnoise.py new file mode 100644 index 000000000..fcab5ac15 --- /dev/null +++ b/util/pnoise.py @@ -0,0 +1,102 @@ +# +# A python perlin noise implementation, from +# http://www.fundza.com/c4serious/noise/perlin/perlin.html +# +# This is used for testing how to create maps with a python script. +# + +import math +p = ( +151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103, +30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197, +62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, +125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231, +83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102, +143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200, +196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, +250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16, +58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70, +221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113, +224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144, +12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181, +199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236, +205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, +151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103, +30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197, +62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20, +125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231, +83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102, +143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200, +196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, +250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16, +58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70, +221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113, +224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144, +12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181, +199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236, +205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180) + +def lerp(t, a, b): + return a + t * (b - a) + +def fade(t): + return t * t * t * (t * (t * 6 - 15) + 10) + +def grad(hash, x, y, z): + h = hash & 15 + if h < 8: + u = x + else: + u = y + if h < 4: + v = y + elif h == 12 or h == 14: + v = x + else: + v = z + if h & 1 != 0: + u = -u + if h & 2 != 0: + v = -v + return u + v + +def pnoise(x, y, z): + global p + X = int(math.floor(x)) & 255 + Y = int(math.floor(y)) & 255 + Z = int(math.floor(z)) & 255 + x -= math.floor(x) + y -= math.floor(y) + z -= math.floor(z) + + u = fade(x) + v = fade(y) + w = fade(z) + + A = p[X] + Y + AA = p[A] + Z + AB = p[A + 1] + Z + B = p[X + 1] + Y + BA = p[B] + Z + BB = p[B + 1] + Z + + pAA = p[AA] + pAB = p[AB] + pBA = p[BA] + pBB = p[BB] + pAA1 = p[AA + 1] + pBA1 = p[BA + 1] + pAB1 = p[AB + 1] + pBB1 = p[BB + 1] + + gradAA = grad(pAA, x, y, z) + gradBA = grad(pBA, x-1, y, z) + gradAB = grad(pAB, x, y-1, z) + gradBB = grad(pBB, x-1, y-1, z) + gradAA1 = grad(pAA1,x, y, z-1) + gradBA1 = grad(pBA1,x-1, y, z-1) + gradAB1 = grad(pAB1,x, y-1, z-1) + gradBB1 = grad(pBB1,x-1, y-1, z-1) + return lerp(w, + lerp(v, lerp(u, gradAA, gradBA), lerp(u, gradAB, gradBB)), + lerp(v, lerp(u, gradAA1,gradBA1),lerp(u, gradAB1,gradBB1))) -- cgit v1.2.3 From b55d2d4a6509908485b1f192b8977cbe38d03311 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 25 Jun 2011 17:46:08 +0300 Subject: added minetestmapper in utils/ --- util/colors.txt | 21 +++ util/minetestmapper.py | 444 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 465 insertions(+) create mode 100644 util/colors.txt create mode 100755 util/minetestmapper.py (limited to 'util') diff --git a/util/colors.txt b/util/colors.txt new file mode 100644 index 000000000..c16fd3e23 --- /dev/null +++ b/util/colors.txt @@ -0,0 +1,21 @@ +0 128 128 128 +1 107 134 51 +2 39 66 106 +3 255 255 0 +4 86 58 31 +5 48 95 8 +6 102 129 38 +7 178 178 0 +8 101 84 36 +9 39 66 106 +12 104 78 42 +13 210 194 156 +14 117 86 41 +15 128 79 0 +16 118 118 118 +18 123 123 123 +19 199 199 199 +20 183 183 222 +21 103 78 42 +22 108 138 108 +23 90 90 90 diff --git a/util/minetestmapper.py b/util/minetestmapper.py new file mode 100755 index 000000000..5f3aab456 --- /dev/null +++ b/util/minetestmapper.py @@ -0,0 +1,444 @@ +#!/usr/bin/python2 +# -*- coding: windows-1252 -*- + +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# COPYING for more details. + +# Made by Jogge, modified by celeron55 +# 2011-05-29: j0gge: initial release +# 2011-05-30: celeron55: simultaneous support for sectors/sectors2, removed +# 2011-06-02: j0gge: command line parameters, coordinates, players, ... +# 2011-06-04: celeron55: added #!/usr/bin/python2 and converted \r\n to \n +# to make it easily executable on Linux + +# Requires Python Imaging Library: http://www.pythonware.com/products/pil/ + +# Some speed-up: ...lol, actually it slows it down. +#import psyco ; psyco.full() +#from psyco.classes import * + +import zlib +import Image, ImageDraw, ImageFont, ImageColor +import os +import string +import time +import getopt +import sys + +def hex_to_int(h): + i = int(h, 16) + if(i > 2047): + i -= 4096 + return i + +def hex4_to_int(h): + i = int(h, 16) + if(i > 32767): + i -= 65536 + return i + +def int_to_hex3(i): + if(i < 0): + return "%03X" % (i + 4096) + else: + return "%03X" % i + +def int_to_hex4(i): + if(i < 0): + return "%04X" % (i + 65536) + else: + return "%04X" % i + +def limit(i, l, h): + if(i > h): + i = h + if(i < l): + i = l + return i + +def usage(): + print "TODO: Help" +try: + opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=", "output=", "bgcolor=", "scalecolor=", "origincolor=", "playercolor=", "draworigin", "drawplayers", "drawscale"]) +except getopt.GetoptError, err: + # print help information and exit: + print str(err) # will print something like "option -a not recognized" + usage() + sys.exit(2) + +path = "../world/" +output = "uloste.png" +border = 0 +scalecolor = "black" +bgcolor = "white" +origincolor = "red" +playercolor = "red" +drawscale = False +drawplayers = False +draworigin = False + +sector_xmin = -1500 / 16 +sector_xmax = 1500 / 16 +sector_zmin = -1500 / 16 +sector_zmax = 1500 / 16 + +for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + elif o in ("-i", "--input"): + path = a + elif o in ("-o", "--output"): + output = a + elif o == "--bgcolor": + bgcolor = ImageColor.getrgb(a) + elif o == "--scalecolor": + scalecolor = ImageColor.getrgb(a) + elif o == "--playercolor": + playercolor = ImageColor.getrgb(a) + elif o == "--origincolor": + origincolor = ImageColor.getrgb(a) + elif o == "--drawscale": + drawscale = True + border = 40 + elif o == "--drawplayers": + drawplayers = True + elif o == "--draworigin": + draworigin = True + else: + assert False, "unhandled option" + +if path[-1:]!="/" and path[-1:]!="\\": + path = path + "/" + +# Load color information for the blocks. +colors = {} +f = file("colors.txt") +for line in f: + values = string.split(line) + colors[int(values[0])] = (int(values[1]), int(values[2]), int(values[3])) +f.close() + +xlist = [] +zlist = [] + +# List all sectors to memory and calculate the width and heigth of the resulting picture. +try: + for filename in os.listdir(path + "sectors2"): + for filename2 in os.listdir(path + "sectors2/" + filename): + x = hex_to_int(filename) + z = hex_to_int(filename2) + if x < sector_xmin or x > sector_xmax: + continue + if z < sector_zmin or z > sector_zmax: + continue + xlist.append(x) + zlist.append(z) +except OSError: + pass +try: + for filename in os.listdir(path + "sectors"): + x = hex4_to_int(filename[:4]) + z = hex4_to_int(filename[-4:]) + if x < sector_xmin or x > sector_xmax: + continue + if z < sector_zmin or z > sector_zmax: + continue + xlist.append(x) + zlist.append(z) +except OSError: + pass + +minx = min(xlist) +minz = min(zlist) +maxx = max(xlist) +maxz = max(zlist) + +w = (maxx - minx) * 16 + 16 +h = (maxz - minz) * 16 + 16 + +print "w="+str(w)+" h="+str(h) + +im = Image.new("RGB", (w + border, h + border), bgcolor) +draw = ImageDraw.Draw(im) +impix = im.load() + +stuff = {} + +starttime = time.time() + +# Go through all sectors. +for n in range(len(xlist)): + #if n > 500: + # break + if n % 200 == 0: + nowtime = time.time() + dtime = nowtime - starttime + try: + n_per_second = 1.0 * n / dtime + except ZeroDivisionError: + n_per_second = 0 + if n_per_second != 0: + seconds_per_n = 1.0 / n_per_second + time_guess = seconds_per_n * len(xlist) + remaining_s = time_guess - dtime + remaining_minutes = int(remaining_s / 60) + remaining_s -= remaining_minutes * 60; + print("Processing sector "+str(n)+" of "+str(len(xlist)) + +" ("+str(round(100.0*n/len(xlist), 1))+"%)" + +" (ETA: "+str(remaining_minutes)+"m " + +str(int(remaining_s))+"s)") + + xpos = xlist[n] + zpos = zlist[n] + + xhex = int_to_hex3(xpos) + zhex = int_to_hex3(zpos) + xhex4 = int_to_hex4(xpos) + zhex4 = int_to_hex4(zpos) + + sector1 = xhex4.lower() + zhex4.lower() + sector2 = xhex.lower() + "/" + zhex.lower() + + ylist = [] + + sectortype = "" + + try: + for filename in os.listdir(path + "sectors/" + sector1): + if(filename != "meta"): + pos = int(filename, 16) + if(pos > 32767): + pos -= 65536 + ylist.append(pos) + sectortype = "old" + except OSError: + pass + + if sectortype != "old": + try: + for filename in os.listdir(path + "sectors2/" + sector2): + if(filename != "meta"): + pos = int(filename, 16) + if(pos > 32767): + pos -= 65536 + ylist.append(pos) + sectortype = "new" + except OSError: + pass + + if sectortype == "": + continue + + ylist.sort() + + # Make a list of pixels of the sector that are to be looked for. + pixellist = [] + water = {} + for x in range(16): + for z in range(16): + pixellist.append((x, z)) + water[(x, z)] = 0 + + # Go through the Y axis from top to bottom. + ylist2=[] + for ypos in reversed(ylist): + + yhex = int_to_hex4(ypos) + + filename = "" + if sectortype == "old": + filename = path + "sectors/" + sector1 + "/" + yhex.lower() + else: + filename = path + "sectors2/" + sector2 + "/" + yhex.lower() + + f = file(filename, "rb") + + version = f.read(1) + flags = f.read(1) + + # Checking day and night differs -flag + if not ord(flags) & 2: + ylist2.append((ypos,filename)) + f.close() + continue + + dec_o = zlib.decompressobj() + try: + mapdata = dec_o.decompress(f.read()) + except: + mapdata = [] + + f.close() + + if(len(mapdata) < 4096): + print "bad: " + xhex + "/" + zhex + "/" + yhex + " " + str(len(mapdata)) + else: + chunkxpos = xpos * 16 + chunkypos = ypos * 16 + chunkzpos = zpos * 16 + for (x, z) in reversed(pixellist): + for y in reversed(range(16)): + datapos = x + y * 16 + z * 256 + if(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) in colors): + if(ord(mapdata[datapos]) == 2 or ord(mapdata[datapos]) == 9): + water[(x, z)] += 1 + # Add dummy stuff for drawing sea without seabed + stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)]) + else: + pixellist.remove((x, z)) + # Memorize information on the type and height of the block and for drawing the picture. + stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)]) + break + elif(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) not in colors): + print "strange block: " + xhex + "/" + zhex + "/" + yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " palikka: " + str(ord(mapdata[datapos])) + + # After finding all the pixels in the sector, we can move on to the next sector without having to continue the Y axis. + if(len(pixellist) == 0): + break + + if len(pixellist) > 0: + for (ypos, filename) in ylist2: + f = file(filename, "rb") + + version = f.read(1) + flags = f.read(1) + + dec_o = zlib.decompressobj() + try: + mapdata = dec_o.decompress(f.read()) + except: + mapdata = [] + + f.close() + + if(len(mapdata) < 4096): + print "bad: " + xhex + "/" + zhex + "/" + yhex + " " + str(len(mapdata)) + else: + chunkxpos = xpos * 16 + chunkypos = ypos * 16 + chunkzpos = zpos * 16 + for (x, z) in reversed(pixellist): + for y in reversed(range(16)): + datapos = x + y * 16 + z * 256 + if(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) in colors): + if(ord(mapdata[datapos]) == 2 or ord(mapdata[datapos]) == 9): + water[(x, z)] += 1 + # Add dummy stuff for drawing sea without seabed + stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)]) + else: + pixellist.remove((x, z)) + # Memorize information on the type and height of the block and for drawing the picture. + stuff[(chunkxpos + x, chunkzpos + z)] = (chunkypos + y, ord(mapdata[datapos]), water[(x, z)]) + break + elif(ord(mapdata[datapos]) != 254 and ord(mapdata[datapos]) not in colors): + print "outo palikka: " + xhex + "/" + zhex + "/" + yhex + " x: " + str(x) + " y: " + str(y) + " z: " + str(z) + " palikka: " + str(ord(mapdata[datapos])) + + # After finding all the pixels in the sector, we can move on to the next sector without having to continue the Y axis. + if(len(pixellist) == 0): + break + +print "Drawing image" +# Drawing the picture +starttime = time.time() +n = 0 +for (x, z) in stuff.iterkeys(): + if n % 500000 == 0: + nowtime = time.time() + dtime = nowtime - starttime + try: + n_per_second = 1.0 * n / dtime + except ZeroDivisionError: + n_per_second = 0 + if n_per_second != 0: + listlen = len(stuff) + seconds_per_n = 1.0 / n_per_second + time_guess = seconds_per_n * listlen + remaining_s = time_guess - dtime + remaining_minutes = int(remaining_s / 60) + remaining_s -= remaining_minutes * 60; + print("Drawing pixel "+str(n)+" of "+str(listlen) + +" ("+str(round(100.0*n/listlen, 1))+"%)" + +" (ETA: "+str(remaining_minutes)+"m " + +str(int(remaining_s))+"s)") + n += 1 + + (r, g, b) = colors[stuff[(x,z)][1]] + # Comparing heights of a couple of adjacent blocks and changing brightness accordingly. + try: + c1 = stuff[(x - 1, z)][1] + c2 = stuff[(x, z + 1)][1] + c = stuff[(x, z)][1] + if c1 != 2 and c1 != 9 and c2 != 2 and c2 != 9 and c != 2 and c != 9: + y1 = stuff[(x - 1, z)][0] + y2 = stuff[(x, z + 1)][0] + y = stuff[(x, z)][0] + + d = ((y - y1) + (y - y2)) * 12 + else: + d = 0 + + if(d > 36): + d = 36 + + r = limit(r + d, 0, 255) + g = limit(g + d, 0, 255) + b = limit(b + d, 0, 255) + except: + pass + + # Water + if(stuff[(x,z)][2] > 0): + r=int(r * .15 + colors[2][0] * .85) + g=int(g * .15 + colors[2][1] * .85) + b=int(b * .15 + colors[2][2] * .85) + + impix[x - minx * 16 + border, h - 1 - (z - minz * 16) + border] = (r, g, b) + + +if draworigin: + draw.ellipse((minx * -16 - 5 + border, h - minz * -16 - 6 + border, minx * -16 + 5 + border, h - minz * -16 + 4 + border), outline = origincolor) + +font = ImageFont.load_default() + +if drawscale: + draw.text((24, 0), "X", font = font, fill = scalecolor) + draw.text((2, 24), "Z", font = font, fill = scalecolor) + + for n in range(int(minx / -4) * -4, maxx, 4): + draw.text((minx * -16 + n * 16 + 2 + border, 0), str(n * 16), font = font, fill = scalecolor) + draw.line((minx * -16 + n * 16 + border, 0, minx * -16 + n * 16 + border, border - 1), fill = scalecolor) + + for n in range(int(maxz / 4) * 4, minz, -4): + draw.text((2, h - 1 - (n * 16 - minz * 16) + border), str(n * 16), font = font, fill = scalecolor) + draw.line((0, h - 1 - (n * 16 - minz * 16) + border, border - 1, h - 1 - (n * 16 - minz * 16) + border), fill = scalecolor) + +if drawplayers: + try: + for filename in os.listdir(path + "players"): + f = file(path + "players/" + filename) + lines = f.readlines() + name="" + position=[] + for line in lines: + p = string.split(line) + if p[0] == "name": + name = p[2] + print filename + ": name = " + name + if p[0] == "position": + position = string.split(p[2][1:-1], ",") + print filename + ": position = " + p[2] + if len(name) > 0 and len(position) == 3: + x=(int(float(position[0]) / 10 - minx * 16)) + z=int(h - (float(position[2]) / 10 - minz * 16)) + draw.ellipse((x - 2 + border, z - 2 + border, x + 2 + border, z + 2 + border), outline = playercolor) + draw.text((x + 2 + border, z + 2 + border), name, font = font, fill = playercolor) + f.close() + except OSError: + pass + +print "Saving" +im.save(output) -- cgit v1.2.3