本文整理汇总了Python中map.Map.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Map.generate方法的具体用法?Python Map.generate怎么用?Python Map.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.generate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import generate [as 别名]
class Server:
participants = set()
def __init__(self):
self.map = Map()
self.map.generate()
def send(self, player, packet):
print simplejson.dumps(packet)
player.send(packet)
def broadcast(self, packet):
print 'broadcast: ' + simplejson.dumps(packet)
for p in self.participants:
p.send(packet)
示例2: MapDrawer
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import generate [as 别名]
class MapDrawer(object):
def __init__(self):
self.__data=Map()
def map_generate(self):
self.__data.generate()
def get_map_width(self):
return self.__data.width
def get_map_height(self):
return self.__data.height
def get_tile(self,size,value):
waterline = self.__data.waterline
if value <= waterline:
color = (25, 25, value+75)
elif value > waterline and value <= waterline + 10:
color = (value+80, value+80, 100)
elif value > waterline + 10 and value <= waterline + 40:
color = (0, 255-value, 0)
elif value > waterline + 40 and value <= 190:
color = (0, 255-value, 0)
elif value > 190:
color = (255-value, 255-value, 255-value)
tile = pygame.Surface((size, size))
tile.fill(color)
return tile
def get_all_map_image(self,tile_size):
waterline = self.__data.waterline
map_width = self.__data.width
map_height= self.__data.height
map_data = self.__data.map
all_map_image = pygame.Surface((tile_size * map_width,
tile_size * map_height))
for y in range(0, map_height):
for x in range(0, map_width):
value = int(map_data[y][x])
tile = self.get_tile(tile_size,value)
all_map_image.blit(tile,(x*tile_size,y*tile_size))
return all_map_image
def get_all_map_from_storage(self,tile_size):
waterline = self.__data.waterline
map_width = self.__data.width
map_height = self.__data.height
map_data = self.__data.storage[self.data.name]
all_map_image = pygame.Surface((tile_size * map_width,
tile_size * map_height))
for y in range(0, map_height):
for x in range(0, map_width):
if not isinstance(map_data[y][x],list):
value = int(map_data[y][x])
tile = self.get_tile(tile_size,value)
all_map_image.blit(tile,(x*tile_size,y*tile_size))
else:
square = map_data[y][x]
for i in range(0,len(square)):
for j in range(0,len(square)):
value = int(square[i][j])
tile = self.get_tile(tile_size/len(square),value)
all_map_image.blit(tile,(x*tile_size+j*tile_size/len(square),y*tile_size+i*tile_size/len(square)))
return all_map_image
def prepare_map_objects(self,tile_size):
objsd = {}
#objsl = []
for key,value in self.__data.objects_on_map.items():
x,y = key
button = UiButton(name=value,
mode='image',
top=y*tile_size,left=x*tile_size,
width=30,height=30,
image_sourse ='flower',
static=False,
color=(200,60,0))
img_x=value/100
img_y=value%100
button.image1 = ImageStorage()['plants'][img_x][img_y]
button.image2 = ImageStorage()['plants_2'][img_x][img_y]
objsd[(x,y)]=button
#objsl.append(button)
#return (objsd,objsl)
return objsd
示例3: len
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import generate [as 别名]
import math
from xml.etree import ElementTree
import zipfile
import sys
from point import Point
from map import Map
WPT_TAG = "{http://www.topografix.com/GPX/1/0}wpt"
if __name__ == "__main__":
if len(sys.argv) < 4:
print "Usage: python geodistances.py GPX_MAP MAP_DEFINITION OUTPUT_IMAGE"
print "GPX_MAP must be zipped."
print "MAP_DEFINITION must be a XML document"
print "OUTPUT_IMAGE can be in BMP, JPG or PNG (requires libraries when installing PIL)"
else:
# Reads gpx in zip file
file = zipfile.ZipFile(open(sys.argv[1]))
file = file.open(file.namelist()[0])
# Loads all waypoints
wpt_elements = ElementTree.parse(file).getroot().getiterator(WPT_TAG)
points = [Point(math.radians(float(wpt.attrib['lat'])), math.radians(float(wpt.attrib['lon']))) for wpt in wpt_elements]
# Creates map with waypoints and generates image
map = Map(sys.argv[2], points)
output = map.generate()
output.save(sys.argv[3])