本文整理汇总了Python中display.Display.update方法的典型用法代码示例。如果您正苦于以下问题:Python Display.update方法的具体用法?Python Display.update怎么用?Python Display.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类display.Display
的用法示例。
在下文中一共展示了Display.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calibrate_dark_current
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
def calibrate_dark_current(self,max_frames=100):
'''
Collects valid images to calibrate dark current, then sets the dark current correction image. Please block the lamp while this happens.
Arguments:
max_frames: number of frames to record before stopping
'''
# create a dark current collecting pipeline branch on source
# source -> mean
dc_collector = Image_Mean(input=self.source,max_frames=max_frames)
source_display = Display(input=dc_collector,title='dc current source')
source_display.update()
# collect until we have enough data
while( dc_collector.get_frame_count() < dc_collector.get_max_frames() ):
self.source.updatePlayMode()
dc_collector.update()
source_display.update()
#TODO: don't hold up the thread when we do this?
#TODO: maybe have some sort of status bar in the GUI instead?
source_display.close()
# set the dark current image
self.dark_current_image = dc_collector.getOutput(0).getData()
print 'Done collecting dark current calibration data.'
示例2: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class Game(object):
def __init__(self):
self.clock = pygame.time.Clock()
self.display = Display()
self.game_state = GameState()
self.control_state = ControlState()
def run(self):
pygame.init()
while True:
self.control_state.update()
self.game_state.update(self.control_state)
self.display.update(self.game_state)
self.clock.tick(60)
示例3: main
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
def main(stdscr):
curses.curs_set(0)
stdscr.noutrefresh()
main_input = input.Input(stdscr)
main_map = map.Map(100, 100, rooms=20)
player = entity.Entity(*main_map.room_list[0].center.point)
main_map.put_entity(player)
map_display = display.DisplayMapScroll(main_map,
player,
20, 80,
150, 150)
hook_display = display.DisplayHook(map_display,
Orientation.bottom,
4, 20)
hook_to_hook_display = display.DisplayHook(hook_display,
Orientation.right,
4, 10)
map_display.refresh_map()
hook_display.refresh()
hook_to_hook_display.refresh()
Display.update()
done = False
while not done:
key = main_input.get_move_key()
main_map.erase_entity(player)
player.move(key)
main_map.put_entity(player)
hook_display.print_screen(str(player.pos.point), 0, 0)
map_display.refresh_map()
Display.update()
if key == entity.Move.done:
done = True
示例4: calibrate_flat_field_and_color
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
def calibrate_flat_field_and_color(self,max_frames=100):
'''
Collects valid images to calibrate the flat field correction and color correction using CIE XYZ color space. Sets F(x) = (flat field mean intensity) / (flat field correction image), x_mean, z_mean.
Note: needs self.dark_current_image set properly before using.
Please point at a slide or something mostly blank while this happens.
max_frames: number of frames to record before stopping
'''
# create a flat field collection pipeline branch on self.input
# source -> dc corrector -> rgb2xyz -> mean
dc_corrector = Dark_Current_Corrector(input=self.source,
dark_current_image=self.dark_current_image)
source_display = Display(input=dc_corrector,title='ff current source')
source_display.update()
rgb2xyz = ConvertRGBtoXYZ(input=dc_corrector)
rgb2xyz.update()
ff_collector = Image_Mean(input=rgb2xyz, max_frames=max_frames)
# collect until we have enough data
while( ff_collector.get_frame_count() < ff_collector.get_max_frames() ):
self.source.updatePlayMode()
dc_corrector.update()
rgb2xyz.update()
ff_collector.update()
source_display.update()
source_display.close()
# calculate F(x) from Y channel and set flat field image
# F(x) = F(x) = (ff mean intensity) / (ff correction image)
flat_field_image = ff_collector.getOutput(0).getData()[:,:,1].astype(numpy.float)
self.flat_field_image = flat_field_image.mean() / flat_field_image
self.x_mean = ff_collector.getOutput(0).getData()[:,:,0].mean()
self.z_mean = ff_collector.getOutput(0).getData()[:,:,2].mean()
print self.x_mean, self.z_mean
print 'Done collecting flat field calibration data.'
示例5: Life
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class Life(object):
__display = None
grid_size = [100, 100]
def __init__(self):
self.__display = Display(title='PyLife', grid_size=self.grid_size, width=800, height=800)
def initial_seed(self):
cells = {}
for x in range(self.grid_size[0]):
for y in range(self.grid_size[1]):
if random.randint(0, 1) == 1:
cells[(x, y)] = 1
return cells
def get_cell_neighbours(self, item, cells):
neighbours = 0
for x in range(-1, 2):
for y in range(-1, 2):
cell = (item[0] + x, item[1] + y)
if cell[0] in range(0, self.grid_size[0]) and cell[1] in range(0, self.grid_size[1]) and cell in cells:
if (x == 0 and y == 0) is False:
neighbours += 1
return neighbours
def get_cells(self, cells):
new_cells = {}
for x in range(self.grid_size[0]):
for y in range(self.grid_size[1]):
neighbours = self.get_cell_neighbours((x, y), cells)
if ((x, y) in cells) and (neighbours == 2 or neighbours == 3):
new_cells[(x, y)] = 1
elif ((x, y) in cells) is False and neighbours == 3:
new_cells[(x, y)] = 1
del cells
return new_cells
def run(self):
cells = self.initial_seed()
while True:
if self.__display.update() is False:
self.__display.quit()
sys.exit(0)
cells = self.get_cells(cells)
for cell in cells:
self.__display.draw(cell[0], cell[1])
示例6: Dala
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class Dala(object):
def __init__(self, debug=False, headless=False):
self.debug = debug
self.game = DalaGame()
self.headless = headless
self.updated = True
pygame.init()
self.clock = pygame.time.Clock()
if not self.headless:
self._init_display()
def _init_display(self):
self.display = Display(title='Dala', clock=self.clock)
def _update_display(self):
if self.updated or True:
self.display.update(self.game)
self.updated = False
def reset(self):
pass
def main(self):
self.display.display_opening()
while True:
event = pygame.event.wait()
self._process_restart(event)
self._process_quit(event)
if self._is_mouse_up(event):
pos = pygame.mouse.get_pos()
position = self.display.get_board_position(pos)
if position is not None:
if self.game.game_mode() == DalaGame.drop_mode:
if not self._drop_loop(position):
self.display.board.clear_candidates()
elif self.game.game_mode() == DalaGame.move_mode:
if not self._move_loop(position):
self.display.board.clear_candidates()
elif event.type == pygame.MOUSEMOTION:
position = self.display.get_board_position(
pygame.mouse.get_pos())
if self.game.game_mode() == DalaGame.drop_mode:
self.display.board.update_drop_candidate(self.game,
position)
elif self.game.game_mode() == DalaGame.move_mode:
self.display.board.update_source_candidate(self.game,
position)
self._update_display()
def _is_mouse_up(self, event, button=MouseButtons.left):
return event.type == pygame.MOUSEBUTTONUP and event.button == button
def _move_loop(self, source):
r, c = source
if self.game._board[r][c] == self.game.whos_turn():
self.display.board.update_source_candidate(self.game, source)
while True:
event = pygame.event.wait()
self._process_restart(event)
self._process_quit(event)
if event.type == pygame.MOUSEMOTION:
pos = pygame.mouse.get_pos()
dest = self.display.get_board_position(pos)
self.display.board.update_destination_candidate(self.game,
dest)
elif self._is_mouse_up(event, MouseButtons.right):
return False
elif self._is_mouse_up(event):
pos = pygame.mouse.get_pos()
dest = self.display.get_board_position(pos)
try:
if dest is not None:
self.game.move(self.game.whos_turn(), source, dest)
return True
except MustCaptureException:
self.display.board.update_destination_candidate(
self.game, dest)
def action(dala_game, capture):
dala_game.move(dala_game.whos_turn(), source, dest,
capture)
if self._capture_loop(action):
return True
#.........这里部分代码省略.........
示例7: Display
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
display = Display()
lcd = display.lcd
prevButton = -1
lastTime = time.time()
REFRESH_TIME = 2.0
# show first page
display.show()
while True:
button = lcd.buttons()
if button is not prevButton:
if lcd.buttonPressed(lcd.UP):
display.moveUp()
display.show()
elif lcd.buttonPressed(lcd.DOWN):
display.moveDown()
display.show()
elif lcd.buttonPressed(lcd.SELECT):
display.action()
prevButton = button
lastTime = time.time()
else:
now = time.time()
since = now - lastTime
if since > REFRESH_TIME or since < 0.0:
display.update()
lastTime = now
示例8: readline_from_socket
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect(("127.0.0.1", 5050))
display = None
board = None
players = None
for line in readline_from_socket(s):
try:
data = json.loads(line)
if not display:
board = GameBoardClient(*data["map_size"])
players = [Player(None, name=player["name"]) for player in data["players"]]
display = Display(600, 600, board.width, board.height)
display.init()
board.update(data["map"])
display.clear()
display.draw_board(board, players)
display.update(fps=0)
except Exception, e:
print("Error parsing:", e.message)
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Game terminated by host.")
sys.exit(0)
示例9: __init__
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class GameServer:
def __init__(self, port, mapfile, rounds_per_second, w, h, observers):
self._port = port
self.players = []
self.observers = []
self.numObservers = observers
self.numPlayers = 0 # Will be overwritten by loadmap. (but included here to make PyCharm happy)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(('', port))
self.socket.listen(3)
self.loadmap(mapfile)
self.display = Display(w, h, self.board.width, self.board.height)
self.rounds_per_second = rounds_per_second
def start(self):
print("Server started on port {}.".format(self._port))
self.wait_for_observsers()
self.wait_for_players()
print("All players are ready, game is now starting.")
self.send_gamestate_to_observers(unfiltered=True)
self.display.init()
first_round = True
while True:
self.display.clear()
self.start_next_turn()
self.resolve_food_harvest()
self.move_and_spawn_units()
self.resolve_fights()
self.destroy_spawners()
if random.randrange(0, 100) < 17:
self.board.spawn_food()
self.send_gamestate_to_players()
self.send_gamestate_to_observers()
self.display.draw_board(self.board, self.players)
if first_round:
self.wait_for_next_round(1)
first_round = False
if self.wait_for_next_round(self.rounds_per_second):
return True
def wait_for_next_round(self, rounds_per_seconds):
num_updates = int(20 / rounds_per_seconds)
for _ in range(num_updates):
self.display.update(20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Game terminated by host.")
return True
return False
def wait_for_observsers(self):
print("Waiting for {} observer(s) to connect...".format(self.numObservers))
for _ in range(self.numObservers):
observer = self.get_player_from_socket()
observer.name = "Observer"
self.observers.append(observer)
def wait_for_players(self):
print("Waiting for {} player(s) to connect...".format(self.numPlayers))
for _ in range(self.numPlayers):
player = self.get_player_from_socket()
player.start()
self.players.append(player)
while not self.check_players_ready():
time.sleep(0.5)
def start_next_turn(self):
for player in self.players:
player.start_next_turn()
def get_player_from_socket(self):
conn, addr = self.socket.accept()
print("Recieved new connection from {}:{}".format(*addr))
return Player(conn)
def check_players_ready(self):
for player in self.players:
if not player.ready:
return False
return True
def move_and_spawn_units(self):
for playerNum, player in enumerate(self.players):
# Set new spawning mode for the player
mode = player.command.get("mode", "standard")
if mode == "standard":
player.mode = Unit
elif mode == "harvester":
player.mode = Harvester
elif mode == "soldier":
player.mode = Soldier
# move all the units he sent a command for
#.........这里部分代码省略.........
示例10: Viewport
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class Viewport(ScaledObject, Scaled):
"""
A `Scaleable` view onto some object.
"""
def __init__(self, size, scale, target=None, boundBox=Object(), maxBounds=None):
"""
`size` - The size (width and height).
`scale` - The scale at which to render the view.
`target` - (Optional) An object that the position of the `Viewport` should follows. If
not set, the `Viewport` will not move automatically.
`boundBox` - (Optional) A sub-view of the `Viewport`, inside which the `target` should
always remain. If not set, it will be set to the Viewport's size.
`maxBounds` - (Optional) A Rectangle inside of which the `Viewport` should always remain.
If not set, there will be no max/min bounds on the position of the `Viewport`.
"""
super().__init__(size=size, scale=scale)
self._target = target
self._boundBox = ScaledOffsetObject(rect=boundBox, scale=self.getScale)
self._maxBounds = maxBounds
self._display = Display(Surface(size))
self._displaySurfaceCache = self._display.getImage()
self._surfaceCache = None
self._lastScale = None
def getAbsolutePos(self, pos):
"""
Returns the `pos` converted into terms of the `Viewport`.
This is important when the scale is not 1 because the on-screen position will not
match the actual position being passed in at arbitrary scales.
"""
return self.x + (pos[0] * self.getScale()), self.y + (pos[1] * self.getScale())
def tick(self):
"""
Adjusts the position of the `Viewport` to keep the `target` inside `boundBox`, and
to keep the `Viewport` inside `maxBounds`.
"""
# Adjusts x and y to relative to the target.
if self._target:
if self.x > self._target.x - self._boundBox.x:
self.x = self._target.x - self._boundBox.x
if self.x < self._target.x + self._target.w + self._boundBox.w - self.w:
self.x = self._target.x + self._target.w + self._boundBox.w - self.w
if self.y > self._target.y - self._boundBox.y:
self.y = self._target.y - self._boundBox.y
if self.y < self._target.y + self._target.h + self._boundBox.h - self.h:
self.y = self._target.y + self._target.h + self._boundBox.h - self.h
# Adjusts x and y relative to the maximum/minimum bounds.
if self._maxBounds:
if self.x < self._maxBounds.x:
self.x = self._maxBounds.x
if self.x + self.w > self._maxBounds.w:
self.x = self._maxBounds.w - self.w
if (self.x < 0) and (self.x + self.w > self._maxBounds.w):
self.x = self._target.x + self._target.w / 2 - self.w / 2
if self.y < self._maxBounds.y:
self.y = self._maxBounds.y
if self.y + self.h > self._maxBounds.h:
self.y = self._maxBounds.h - self.h
if (self.y < 0) and (self.y + self.h > self._maxBounds.h):
self.y = self._target.y + self._target.h / 2 - self.h / 2
def draw(self, surface, total_surface):
"""
Calculate the scaling and display to the inputted surface.
`surface` - The `Surface` being drawn to.
`total_surface` - The `Surface` being copied from.
"""
scale = self.getScale()
# Optimization, no need to do scaling when the scale is 1.
if scale == 1:
self._display.update(total_surface, Display.translate(total_surface.get_rect(), self))
else:
# Optimization, caches the `Surface` object so long as the scale isn't changing.
if scale != self._lastScale:
self._surfaceCache = Surface((self.w, self.h))
self._surfaceCache.blit(total_surface, (-self.x, -self.y))
scaleTo = self.unscaled()
transform.scale(self._surfaceCache, (scaleTo.w, scaleTo.h), self._displaySurfaceCache)
self._lastScale = scale
self._display.draw(surface)
示例11: Map
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
#.........这里部分代码省略.........
strToClass = globals()['__builtins__']
result = {}
sectionMatch = r"^\s*{0}:\s*".format(attrName)
attrSet = re.search(r"{0}\{{(.*?)\}}".format(sectionMatch), data, flags=(re.DOTALL | re.MULTILINE)).groups()[0]
def do_nothing(input):
return input.group()
def capture_tuple(input):
cast_str, key = input.groups()
cast = strToClass[cast_str]
return tuple(cast(i) for i in key.split(', ') if cast)
attrMatches = [(r"(\w+)", do_nothing), (r"(\w*)\((\w+,\s*\w+)\)", capture_tuple)]
total_line_match = r"^\s*(.*?):\s*\((\w+)\)(.*),$"
singleKeyMatch = re.finditer(total_line_match, attrSet, flags=re.MULTILINE)
for match in singleKeyMatch:
for attrMatch, key_func in attrMatches:
name, typ, value = match.groups()
name_match = re.match(r"^{}$".format(attrMatch), name)
if name_match:
result[key_func(name_match)] = strToClass[typ](value)
return result
@property
def enemies(self):
return self._enemies.copy()
def load(self):
self._map = {}
self._tiles = {}
self._attributes = {}
file = Files.openFile(self._file)
self._attributes = self.loadAttributes('attribs', file)
self._enemies = self.loadAttributes('enemies', file)
self.w = self.getAttr("w") * const.res
self.h = self.getAttr("h") * const.res
self._display = Display(Surface((self.w, self.h)), klass=self, transparent=True)
file = re.search("map: {(.*?)}", file, flags=re.DOTALL).group(1)
for tile in re.finditer(r"\((.*?):(.*?)\)", file):
rect, right = tile.group(1), tile.group(2)
rect = re.match(r"(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)", rect)
if not rect:
raise Exception("Unrecognized pattern: {}".format(rect))
details = re.match(r"(\d+),(\d+)$", right)
if not details:
raise Exception("Unrecognized pattern: {}".format(right))
i, e = int(rect.group(1)), int(rect.group(2))
x, y, w, h = rect.group(3), rect.group(4), rect.group(5), rect.group(6)
x, y, w, h = int(x), int(y), int(w), int(h)
typ, tile = int(details.group(1)), int(details.group(2))
attrib = {}
wall = Wall((x, y, w, h), typ, tile, attrib)
wall.subscribe("map", self._updateMap)
self._map[(i, e)] = wall
self._tiles.setdefault(wall.getType(), []).append(wall)
def save(self):
s = []
s.append("attribs: {\n")
for a, val in self._attributes.items():
s.append(" {}: {},\n".format(a, val))
s.append("}\n")
s.append("map: {\n")
for i in range(self.getAttr("h")):
for e in range(self.getAttr("w")):
tile = self._map[(e, i)]
s.append("({},{},{},{},{},{}:{},{}".format(e, i,
tile.x, tile.y,
tile.w, tile.h,
tile.getType().value,
tile.getTile()))
spawn = tile.getAttr("spawnNum")
if spawn:
s.append(",[{}]".format(str(spawn)))
s.append(")")
s.append("\n")
s.append("}")
Files.saveFile(self._file, ''.join(s))
def _updateMap(self, block):
try:
self._tiles.setdefault(block.getType(), []).remove(block)
except ValueError:
pass
self._tiles.setdefault(block.getType(), []).append(block)
self._display.update(Surface((const.res, const.res)), block)
self._display.update(self._tileset,
Object(rect=(block.mapX * const.res, block.mapY * const.res,
const.res, const.res)),
Object(rect=(0, block.getTile() * const.res, const.res, const.res)))
示例12: __init__
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class GameAI:
def __init__(self, name):
self.name = name
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.display = None
self.board = None
self.players = None
self.my_id = None
def sendline(self, line):
self.sock.send((line+"\n").encode('UTF-8'))
def send_command(self, command):
self.sendline(json.dumps(command))
def start(self, ip, port):
self.sock.connect((ip, port))
self.sendline("name {}".format(self.name))
for line in readline_from_socket(self.sock):
data = json.loads(line)
if "status" in data:
self.handle_status_message(data)
continue
if not self.display:
self.board = GameBoardClient(*data["map_size"])
self.players = [Player(None, name="Player"+str(i)) for i in range(data["num_players"])]
self.my_id = data["player_id"]
self.players[self.my_id].name = self.name
self.display = Display(600, 600, self.board.width, self.board.height)
self.display.init()
self.board.update(data["map"])
self.display.clear()
self.display.draw_board(self.board, self.players)
self.display.update(fps=0)
self.resolve_round()
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Game terminated by host.")
sys.exit(0)
def handle_status_message(self, command):
'''
Implement how to handle status-messages here. The current implementation
will ignore any "Status OK" and print everything else.
:param command: The data recieved from server (must be a status message)
'''
if command.get("status", "ok").lower() != "ok":
print("Status: {} - Message: {}".format(command.get("status", "ok"), command.get("msg", "")))
def resolve_round(self):
'''
This function will be called once each turn. Any login with the AI should be implemented here.
Make sure that this command sends a new command to the server before it returns.
The map-state is stored in self.board.
'''
# Simple implementation
command = {"mode": random.choice(["standard", "harvester", "soldier"]), "moves": []}
for unit in filter(lambda u: u.owner == self.my_id, self.board.units):
x, y = unit.position
legal_directions = ["north", "south", "west", "east"]
direction = random.choice(legal_directions)
command["moves"].append([x, y, direction])
self.board.move_unit(x, y, direction)
self.send_command(command)
示例13: __init__
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
class Carte:
"""Represent a map containing BTS and MS"""
def __init__(self, width=800, height=600):
(self.__width, self.__height) = (width, height)
self.__display = Display(width, height)
self.__bts = {}
self.__ms = set()
self.__color_index = 0
self.__filename = None
self.__speed = 1.
self.__freqs_color = {}
log.nb_handover = 0
self.__display.action_load.triggered.connect(self.load_file)
self.__display.action_reload.triggered.connect(self.reload_file)
self.__display.action_play.triggered.connect(self.__update_moving_ms)
self.__display.action_incSpeed.triggered.connect(
lambda: self.change_speed(1))
self.__display.action_decSpeed.triggered.connect(
lambda: self.change_speed(-1))
self.__display.speed_lineedit.editingFinished.connect(
lambda: self.set_speed(float(self.__display.speed_lineedit.text())))
self.__move_timer = QtCore.QTimer()
self.__move_timer.timeout.connect(self.movems)
self.set_speed(1)
self.__display.show()
def add(self, elem):
"""Add an element on map"""
# Add a BTS and update all MS
if isinstance(elem, BTS):
if not elem.f in self.__freqs_color:
self.__freqs_color[elem.f] = len(self.__freqs_color) + 1
idx_color = self.__freqs_color[elem.f]
color = get_color(idx_color, elem.network == "GSM")
self.__bts[elem] = QtGui.QColor(*color)
bts_set = set(self.__bts.keys())
for ms in self.__ms:
ms.update_bts_list(bts_set)
# Add a MS and update it with BTS list
elif isinstance(elem, MS):
self.__ms.add(elem)
elem.set_speed(self.__speed)
elem.update_bts_list(set(self.__bts.keys()))
else:
return
self.refresh()
def refresh(self):
"""Refresh map display"""
self.__display.clean()
for (bts, color) in self.__bts.iteritems():
self.__display.draw(bts, color)
for ms in self.__ms:
self.__display.draw(ms, self.__bts[ms.bts])
self.__display.update()
def change_speed(self, offset):
"""Change map speed with offset"""
self.set_speed(self.__speed + offset)
def set_speed(self, speed):
"""Set map speed"""
speed = float(min(5, max(0, speed)))
self.__move_timer.setInterval(800/pow(2, speed-1))
self.__speed = speed
for ms in self.__ms:
ms.set_speed(speed)
self.__display.speed_lineedit.setText(str(self.__speed))
def movems(self):
"""Move all MS"""
for ms in self.__ms:
ms.random_move(self.__width-1, self.__height-1)
self.refresh()
def start_moving_ms(self):
"""Start movin MS on map"""
self.__move_timer.start()
def __update_moving_ms(self):
"""Update MS movig state according to interface"""
if self.__display.action_play.isChecked():
self.__move_timer.stop()
else:
self.__move_timer.start()
def load_file(self, filename=None):
"""Load an xml file"""
if not filename:
#.........这里部分代码省略.........
示例14: OrbitalBody
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
#asteroid= OrbitalBody(position, speed, mass, RADIUS)
CelestialCluster.init()
distancia_corpos = []
from display import Display
os.environ['SDL_VIDEO_WINDOW_POS'] = "0, 0"
#--MAIN LOOP--
while not SysComm.quit:
current_time= gtime.current()
#update system interface
SysComm.update()
#update things
CelestialCluster.update()
Perspective.update()
#draw things
Display.update()
gtime.update()
elapsed_time= gtime.current()-current_time
if elapsed_time < 16:
gtime.sleep( 16 - elapsed_time)
#print(distancia_corpos)
#grafico(ticks,distancia_corpos,gtime.RESOLUTION)
#distancia_corpos.append(distancia_2_planetas(celestial_cluster.cluster,color.EARTH,color.SUN))
示例15: xrange
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import update [as 别名]
delta_d = 5
elif e.key == pg.K_DOWN:
delta_d = -5
elif e.key == pg.K_s:
print "save..."
world.save("worldsave")
elif e.key == pg.K_l:
print "load..."
world = PhyWorld.load("worldsave")
disp.world = world
elif e.key == pg.K_LEFT:
delta_angle = pi / 20
elif e.key == pg.K_RIGHT:
delta_angle = -pi / 20
elif e.type == pg.KEYUP:
delta_d = 0
delta_angle = 0
viewport.s[1, 0] += delta_d
viewport.rotate((0, 0, 0), (0, 0, 1), delta_angle)
for i in xrange(config.PhyFPS / config.FPS):
world.update()
disp.update()
# raw_input("press enter to continue")
fps_timer.tick(config.FPS)
fff += 1
if fff == 30:
print "FPS", fps_timer.get_fps()
fff = 0