本文整理汇总了Python中map.Map类的典型用法代码示例。如果您正苦于以下问题:Python Map类的具体用法?Python Map怎么用?Python Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: endCapture
def endCapture(self):
if (self.mBrushBehavior != BrushBehavior.Capture):
return
self.mBrushBehavior = BrushBehavior.Free
tileLayer = self.currentTileLayer()
# Intersect with the layer and translate to layer coordinates
captured = self.capturedArea()
captured &= QRect(tileLayer.x(), tileLayer.y(),
tileLayer.width(), tileLayer.height())
if (captured.isValid()):
captured.translate(-tileLayer.x(), -tileLayer.y())
map = tileLayer.map()
capture = tileLayer.copy(captured)
stamp = Map(map.orientation(),
capture.width(),
capture.height(),
map.tileWidth(),
map.tileHeight())
# Add tileset references to map
for tileset in capture.usedTilesets():
stamp.addTileset(tileset)
stamp.addLayer(capture)
self.stampCaptured.emit(TileStamp(stamp))
else:
self.updatePreview()
示例2: testParticleFilter
def testParticleFilter():
print 'Testing the ParticleFilter class ...'
# Read map
map = Map()
map.readMap('../data/map/wean.dat')
# basic tests
filter = ParticleFilter()
filter.initParticles(map)
X = [Particle(0,0,0, 0.1), Particle(0,0,0, 0.1), Particle(0,0,0, 0.1)]
print 'X after resampling', filter._resample(X)
# test for update function
pos = filter._update((5.0, 6.0, 0.0), (1, 2, 0.0), (2, 2, 0.0))
print pos # this should print something close to (6, 6, 0)
'''
ind = weighted_choice([0.4, 0, 0])
if ind != 0:
print 'FAILED weighted_choice test.'
ind = weighted_choice([0.4, .6, 0.2])
print 'ind = ', ind
'''
return
示例3: build
def build(self):
#create window
root = Widget()
root.size = Window.size
root.center = Window.center
#create map
Map.tileSet = TileFactory
board = Map(size=(504,504))
root.add_widget(board.getDisplayRoot())
#add starting tile
tile_fact = TileFactory()
for i in range(1):
btn = tile_fact.newTile(board)
board.addPiece(btn,(i*126,i*126))
#create players
CurrentTile.map = board
CurrentTile.tile_size = TileFactory.size
playerTile = CurrentTile()
newTile = tile_fact.newTile(board)
root.add_widget(playerTile)
playerTile.resetTile(newTile)
return root
示例4: Game
class Game(object):
def __init__(self):
pygame.init()
self.window = pygame.display.set_mode((640, 480))
self.player = Player(x=100, y=100, width=640, height=480)
self.plupp = Plupp(window_width=640, window_height=480)
self.clock = pygame.time.Clock()
self.map = Map()
while True:
CollisionHandler.handle_plupp_collisions(player=self.player, plupp=self.plupp)
CollisionHandler.handle_player_collisions(player=self.player, map=self.map)
EventHandler.handle_events(player=self.player, plupp=self.plupp)
self.clock.tick(15)
self.update()
self.draw()
def update(self):
self.player.update()
def draw(self):
self.window.fill((0, 0, 255))
self.player.draw(self.window)
self.plupp.draw(self.window)
self.map.draw(self.window)
pygame.display.flip()
示例5: __init__
class GameState:
def __init__(self):
self.controller = Controller(self)
self.side = PlayerSide(self)
self.map = Map(self)
self.gui = GameStateGUI(self)
def handleEvents(self,events):
self.controller.handleEvents(events)
def tick(self):
self.map.tick()
self.side.tick()
def blit(self,screen):
screen.fill((0,0,0))
self.map.blit(screen)
self.side.blit(screen)
self.gui.blit(screen)
if self.controller.action[0] == PLACEOBJECT:
screen.blit(R.IMAGES[R.buildings[self.controller.action[1]]["image"]],(pygame.mouse.get_pos()[0]/20*20+self.map.offset[0]%20,
pygame.mouse.get_pos()[1]/20*20+self.map.offset[1]%20))
示例6: test
def test():
the_map = Map()
tic = time.clock()
the_map.discretize_map()
print time.clock() - tic
#obstacle = Polygon([(40,15), (45,15), (45,20), (40,20)], safety_region_length=4.0)
#the_map.add_obstacles([obstacle])
tend = 10
dT = 1
h = 0.05
N = int(tend/h) + 1
N2 = int(tend/dT) + 1
x0 = np.array([10, 10, 0.0, 3.0, 0, 0])
xg = np.array([50, 50, 0])
myDynWnd = DynamicWindow(dT, N2)
v = Vessel(x0, xg, h, dT, N, [myDynWnd], is_main_vessel=True, vesseltype='viknes')
v.current_goal = np.array([50, 50])
world = World([v], the_map)
myDynWnd.the_world = world
world.update_world(0,0)
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal', autoscale_on=False,
xlim=(-10, 160), ylim=(-10, 160))
world.visualize(ax, 0, 0)
plt.show()
示例7: test_all_trips_3
def test_all_trips_3(self):
map = Map(1, 2, 3)
map.append(1, 3, 1)
map.append(3, 1, 1)
accept_func = lambda step, distance: True
trim_func = lambda step, distance: step > 5
self.assertEqual(map.all_trips(1, 3, accept_func, trim_func), 3)
示例8: update_pos_by_dist_and_dir
def update_pos_by_dist_and_dir(self, distance, direction):
"""
params:
distance - distance went through
direction - angles relative to the west (clockwise)
"""
dirRelativeNorth = Map.get_direction_relative_north(self.building, self.level, direction)
northAt = Map.get_north_at(self.building, self.level)
userDir = dirRelativeNorth + northAt # relative to map
userDir = userDir % 360
if not self.nextLoc:
self.nextLoc = self.get_next_location(self.pos[0], self.pos[1])
movingDir = Map.get_direction(self.pos[0], self.nextLoc["x"],
self.pos[1], self.nextLoc["y"]) # relative to map
relativeDir = movingDir - userDir
# if relativeDir > 0, it's at user's rhs, else lhs
if relativeDir > 180:
relativeDir -= 360
if relativeDir < -180:
relativeDir += 360
(x, y, newDir) = Map.get_direction_details(self.building, self.level, distance, direction + relativeDir)
vec1X = self.pos[0] - float(self.nextLoc["x"])
vec1Y = self.pos[1] - float(self.nextLoc["y"])
vec2X = self.pos[0] + x - float(self.nextLoc["x"])
vec2Y = self.pos[1] + y - float(self.nextLoc["y"])
isSameDirection = (vec1X * vec2X + vec1Y * vec2Y > 0)
isReachNextLoc = self.is_reach_node(self.nextLoc, self.pos[0] + x, self.pos[1] + y)
isWentPass = not isSameDirection and not isReachNextLoc
if isWentPass:
self.reachedLoc.append(self.nextLoc["nodeName"])
self.update_pos(x, y)
示例9: TestMainSimulation
class TestMainSimulation(unittest.TestCase):
def setUp(self):
self.map=Map('data/londontubes.txt')
self.map.initialise_map()
def test_create_random_target_stations_returns_correct_number(self):
self.target_stations=main.create_random_target_stations(self.map, 800)
self.assertEquals(800, len(self.target_stations))
示例10: new_map
def new_map():
map = Map(join(MAIN_PATH, 'templates', 'Seoul_districts.svg'))
if request.method == 'POST':
req_dict = json.loads(request.data)
print(req_dict)
map.change_color(req_dict)
return redirect('/map')
示例11: get_next_location_details
def get_next_location_details(self, direction, x, y):
"""
params:
current user's direction (relative to north 0~360d), current x & y pos
return:
distance to next loc, direction to next loc (relative to user) & next loc's node
"""
nextLocNode = self.get_next_location(x, y)
if self.nextLoc and self.nextLoc['nodeName'] in self.reachedLoc:
self.prevLoc = self.nextLoc
self.nextLoc = nextLocNode
dist = Map.get_distance(nextLocNode["x"], x, nextLocNode["y"], y)
northAt = Map.get_north_at(self.building, self.level)
userDir = direction + northAt # relative to map
userDir = userDir % 360
movingDir = Map.get_direction(x, nextLocNode["x"],
y, nextLocNode["y"]) # relative to map
relativeDir = movingDir - userDir
# if relativeDir > 0, it's at user's rhs, else lhs
if relativeDir > 180:
relativeDir -= 360
if relativeDir < -180:
relativeDir += 360
return relativeDir, dist, nextLocNode
示例12: do_upload_from_app
def do_upload_from_app():
picture = request.forms.get('picture')
lat = request.forms.get('latitude')
lng = request.forms.get('longitude')
raw = decodestring(picture)
now = datetime.now()
date_filename = now.strftime("%Y%m%d-%H%M%S") + '.jpg'
print date_filename
grid_db = connection['grid_files']
fs = gridfs.GridFS(grid_db)
fs.put(raw, filename=date_filename)
# Insert the filename and other data in the pictures db
hack_db = connection['hackathon']
hack_db.pictures.insert_one(
{'filename': date_filename,
'datetime': now,
'latitude': lat,
'longitude': lng,
'disaster': 0}
)
m = Map(hack_db)
map_id = m.get_map_id(now, [float(lng), float(lat)])
hack_db.pictures.update_one({"filename": date_filename}, {"$set": {"disaster": map_id}})
# Get the image back out
image = fs.get_last_version(filename=date_filename)
bottle.response.content_type = 'image/jpeg'
return image
示例13: enter
def enter():
global timer, player, map, Player_missile, FirstEnemys, SecondEnemys, enemy_missile, enemy_explosion, bomb, bomb_explosion, item, boss, boss_missile
global angle, ui
global score
score = Score()
timer = Timer()
player = Player()
player.kind = 2
map = Map()
map.kind = 2
ui = UI()
bomb = []
FirstEnemys = []
SecondEnemys = []
Player_missile = []
enemy_missile = []
enemy_explosion = []
bomb_explosion = []
item = []
boss = []
boss_missile = [Boss_missile(10,10 ) for i in range(72)]
for member in boss_missile:
angle += 10
if angle >360 :
member.y +=400
member.angle = angle
示例14: __init__
class Game:
def __init__(self, config_filename):
data = json.load(open(config_filename, 'r'))
# init map
self.map = Map(data)
# init player
self.player = Player(data['player'])
def get_current_location_name(self):
return self.map.get_current_location_name()
def get_action(self):
return self.get_action_dic().keys()
def get_action_dic(self):
return self.map.get_current_action()
def play_action(self, action):
action_dic = self.get_action_dic()
action_dic[action](self.player)
def get_player(self):
return self.player
def get_status(self):
status = self.player.get_status()
status['current_location'] = self.get_current_location_name()
return status
示例15: read
def read(self, fileName):
uncompressed = QByteArray()
# Read data
f = QFile(fileName)
if (f.open(QIODevice.ReadOnly)) :
compressed = f.readAll()
f.close()
uncompressed, length = decompress(compressed, 48 * 48)
# Check the data
if (uncompressed.count() != 48 * 48) :
self.mError = self.tr("This is not a valid Droidcraft map file!")
return None
uncompressed = uncompressed.data()
# Build 48 x 48 map
# Create a Map -> Create a Tileset -> Add Tileset to map
# -> Create a TileLayer -> Fill layer -> Add TileLayer to Map
map = Map(Map.Orientation.Orthogonal, 48, 48, 32, 32)
mapTileset = Tileset.create("tileset", 32, 32)
mapTileset.loadFromImage(QImage(":/tileset.png"), "tileset.png")
map.addTileset(mapTileset)
# Fill layer
mapLayer = TileLayer("map", 0, 0, 48, 48)
# Load
for i in range(0, 48 * 48):
tileFile = int(uncompressed[i])&0xff
y = int(i / 48)
x = i - (48 * y)
tile = mapTileset.tileAt(tileFile)
mapLayer.setCell(x, y, Cell(tile))
map.addLayer(mapLayer)
return map