Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Use PIL or Pillow (fork of PIL), either works
- from PIL import Image,ImageDraw
- import json
- data = file("resource_dump.json","rb").read()
- obj = json.loads(data)
- scale = 0.5
- colors = dict()
- # RGB colors for all possible nodes
- # Animals
- colors["AITokarServer"] = (122,201,255)
- colors["AITokarBlueServer"] = (122,201,255)
- colors["AITokarParrotServer"] = (122,201,255)
- colors["AIBorServer"] = (122,201,255)
- colors["AIBorRadServer"] = (122,201,255)
- colors["AIShigiServer"] = (122,201,255)
- colors["AIShigiForestServer"] = (122,201,255)
- colors["AIShigiArcticServer"] = (122,201,255)
- colors["AIShigiWolfServer"] = (122,201,255)
- colors["AIYetiForestServer"] = (122,201,255)
- colors["AIYetiServer"] = (122,201,255)
- # Plants
- colors["OwrongResourceNode"] = (158,255,169)
- colors["PitcherPlantResourceNode"] = (158,255,169)
- colors["SucculentResourceNode"] = (158,255,169)
- # Rocks
- colors["FlintRockResourceNodeServer"] = (0,0,0)
- colors["CoalRockResourceNodeServer"] = (255,128,0)
- colors["SandstoneResourceNodeServer"] = (255,195,160)
- colors["IronRockResourceNodeServer"] = (100,120,140)
- # Rare ores
- colors["Metal2ResourceNodeServer"] = (255,0,0)
- colors["Metal3ResourceNodeServer"] = (0,255,0)
- colors["Metal4ResourceNodeServer"] = (0,0,255)
- # Misc.
- colors["WorldItemFlint"] = (0,0,0)
- colors["LargeMiningRockServer"] = (255,00,128)
- # Wood
- colors["WorldItemWood"] = (227,198,82)
- colors["LogResourceNodeServer"] = (102,51,0)
- colors["Deadtree1ResourceNodeServer"] = (102,51,0)
- colors["Deadtree2ResourceNodeServer"] = (102,51,0)
- colors["Deadtree3ResourceNodeServer"] = (102,51,0)
- spawns = obj["nodes"]
- # Background color to use for the image
- bg_color = (40,40,40)
- # The coordinates in the node array range from roughly -4000.0 - 4000.0 so the full
- # scale would be 8000px. I think the map is actually 10000 pixel but there aren't nodes
- # outside so it doesn't atter
- im = Image.new("RGB",(int(8000*scale),int(8000*scale)),bg_color)
- # Used for single-pixel draw access
- px = im.load()
- # Used for shape drawing
- drw = ImageDraw.Draw(im)
- def draw_box(drw,x,y,col,size=5):
- box = [x-size,y-size,x+size,y+size]
- drw.rectangle(box,fill=col)
- for obj in spawns:
- # Prints
- print obj["Name"]
- for coord in obj["coords"]:
- # Transform coordinates from -4000 ... 4000 range into scaled 0 ... 8000
- x = coord["x"] * scale
- y = coord["y"] * scale
- x += 8000*scale*0.5
- y += 8000*scale*0.5
- if obj["Name"] in colors:
- draw_box(drw,x,y,colors[obj["Name"]],1)
- else:
- print "Warning: Undefined color for node [%s]" % (obj["Name"])
- # This draws a white pixel instead
- px[x,y] = (255,255,255)
- # print "Dimensions: X: %f -> %f Y: %f -> %f" % (low_x,hi_x,low_y,hi_y)
- # We have to flip the image so it's the right orientation
- im = im.transpose(Image.FLIP_TOP_BOTTOM)
- # And render!
- im.save("resource_map.png","PNG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement