Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from xml.dom import minidom
- import re
- from PIL import Image, ImageDraw
- import math
- MAP_X = 801
- MAP_Y = 801
- orange = 'rgb(249,118,3)'
- red = 'rgb(255,0,0)'
- green = 'rgb(51,255,51)'
- gray = 'rgb(192,192,192)'
- yellow = 'rgb(255,255,102)'
- brown = 'rgb(102,51,0)'
- colors = dict( SETTING_ORANGE = orange, \
- FOLDER_ROADS_ORANGE = orange, \
- FOLDER_ROADS_REDROCK = red, \
- SETTING_REDROCK = red, \
- FOLDER_CONCRETE_REDROCK = red, \
- SETTING_GREEN = green, \
- FOLDER_ROADS_GREEN = green, \
- FOLDER_ROCKS = gray, \
- SETTING_YELLOW = yellow, \
- FOLDER_CONCRETE_YELLOW = yellow, \
- FOLDER_ROADS_YELLOW = yellow, \
- SETTING_CAVE = brown, \
- FOLDER_SCHUTT = brown \
- )
- unknown_colors = 'rgb(255,0,127)'
- details = {}
- fp = open('details.txt')
- for line in fp:
- arr = line.split(';')
- if arr[0].isdigit():
- id = arr[0]
- category = arr[2]
- left = int(arr[4])
- top = int(arr[5])
- right = int(arr[6])
- bottom = int(re.sub("^\s+|\n|\r|\s+$", '', arr[7]))
- details[id] = dict( category=category, \
- left=left, \
- top=top, \
- right=right, \
- bottom=bottom \
- )
- # print(details)
- fp.close()
- zone = minidom.parse("zone")
- CY2K_LS_AreaDetails = zone.getElementsByTagName("CY2K_LS_AreaDetails")[0]
- areas = CY2K_LS_AreaDetails.getElementsByTagName('details')
- image = Image.new("RGB", (MAP_X,MAP_Y), (0,0,0,0))
- draw = ImageDraw.Draw(image)
- for area in areas:
- iDetailDefID = area.getElementsByTagName("iDetailDefID")[0].firstChild.data
- if not iDetailDefID in details:
- continue
- fPositionX = float(area.getElementsByTagName("fPositionX")[0].firstChild.data)
- fPositionY = float(area.getElementsByTagName("fPositionY")[0].firstChild.data)
- fRotation = float(area.getElementsByTagName("fRotation")[0].firstChild.data)
- fScaleX = 1 # float(area.getElementsByTagName("fScaleX")[0].firstChild.data)
- fScaleY = 1 # float(area.getElementsByTagName("fScaleY")[0].firstChild.data)
- detail = details[iDetailDefID]
- width = (detail['right'] - detail['left']) * fScaleX
- height = (detail['bottom'] - detail['top']) * fScaleY
- # Ищем левый верхий угол
- angleX = fPositionX - ( width / 2 )
- angleY = fPositionY - ( height / 2 )
- if not detail['category'] in colors:
- color = unknown_colors
- else:
- color = colors[detail['category']]
- print('--------------------------------------------------------')
- print(' iDetailDefID: %s COLOR: %s CATEGORY: %s' \
- % (iDetailDefID, color, detail['category']))
- print(' ScaleX * (right - left) = width %s * (%s - %s) = %s'
- % (fScaleX, detail['right'], detail['left'], width))
- print(' ScaleY * (bottom - top) = height %s * (%s - %s) = %s'
- % (fScaleY, detail['bottom'], detail['top'], height))
- print(' fPositionX - ( width / 2 ) = angleX %s - (%s / 2) = %s '
- % (fPositionX, width, angleX))
- print(' fPositionY - ( height / 2 ) = angleY %s - (%s / 2) = %s '
- % (fPositionY, height, angleY))
- x1 = int(angleX)
- y1 = int(angleY)
- x2 = int(width + angleX)
- y2 = int(height + angleY)
- rect = Image.new("RGB", (x2, y2), color)
- rect.rotate( fRotation, expand=1 )
- image.paste(rect, (x1,y1))
- # draw.rectangle(( x1, y1, x2, y2), fill=color )
- # .rotate( fRotation, expand=1 )
- del draw
- image.save("proto_zone.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement