Skip to content

Instantly share code, notes, and snippets.

@jvranish
Created December 4, 2010 21:56
Show Gist options
  • Save jvranish/728522 to your computer and use it in GitHub Desktop.
Save jvranish/728522 to your computer and use it in GitHub Desktop.
Script to merge a topo map with an overhead map from pynemap
import Image
import math
im = Image.open("minecraft_map_topo.png")
rotatedTopo = im.rotate(-90)
im = Image.open("minecraft_map.png")
rotatedTerrain = im.rotate(-90)
terrainPix = rotatedTerrain.load()
topoPix = rotatedTopo.load()
assert(rotatedTerrain.size == rotatedTopo.size)
def scalePixel(scale, (r, g, b, a)):
return (int(r*scale), int(g*scale), int(b*scale), a)
def topoValue(x, y):
r, g, b, a = topoPix[x, y]
return r - b + 255 - g
width, height = rotatedTerrain.size
for x in xrange(1, width):
for y in xrange(1, height):
delta = (topoValue(x, y) - topoValue(x-1, y))/512.0
# then use magical scaling formula (the hard part is highlighting the small height
# differences without washing out the large height differences
scale = (math.atan(delta*15) + 1.5707963267) / 1.5707963267
terrainPix[x, y] = scalePixel(scale, terrainPix[x, y])
rotatedTerrain.save("minecraft_minimap.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment