本文整理汇总了Python中display.Display.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Display.clear方法的具体用法?Python Display.clear怎么用?Python Display.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类display.Display
的用法示例。
在下文中一共展示了Display.clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Display
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [as 别名]
#!/usr/bin/env python
"""
Plot points from a trackem_ros stream.
SCL; 19 August 2012.
"""
import roslib; roslib.load_manifest("slamsynth_ros")
import rospy
from trackem_ros.msg import *
import numpy as np
from display import Display
if __name__ == "__main__":
rospy.init_node("miniviz")
d = Display(mapsize=[0,3.048,0,3.048]) # in meters
d.marker = 'o' # Backwards compatibility until bentobox.cds is updated
rate = rospy.Rate(10)
while not rospy.is_shutdown():
data = rospy.wait_for_message("trackem/calpoints", MTCalPoints)
points = np.array([[p.x, p.y] for p in data.points])
d.clear()
d.scatter(points.T[0], points.T[1])
d.blit()
rate.sleep()
示例2: Display
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [as 别名]
GPIO.setup(pinRs, GPIO.OUT) # RS
GPIO.setup(pinD4, GPIO.OUT) # DB4
GPIO.setup(pinD5, GPIO.OUT) # DB5
GPIO.setup(pinD6, GPIO.OUT) # DB6
GPIO.setup(pinD7, GPIO.OUT) # DB7
GPIO.output(pinE, False)
GPIO.output(pinRs, False)
GPIO.output(pinD4, False)
GPIO.output(pinD4, False)
GPIO.output(pinD4, False)
GPIO.output(pinD4, False)
display = Display()
display.clear()
#display.printLine(0, "--------------------")
#display.printLine(1, " ")
display.printLine(2, " starting ")
#display.printLine(3, "--------------------")
for i in range(0,4):
symbol = ""
for j in range(0,i):
symbol = symbol + "."
str = " starting " + symbol
display.printLine(2,str)
time.sleep(1)
GPIO.cleanup()
示例3: __init__
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [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
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [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)
示例5: Game
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [as 别名]
class Game(object):
def __init__(self):
self.logger = Logger(level='debug')
self.logger.debug("Create display")
self.display = Display()
self.logger.debug(" + size: %sx%s" % (self.display.width, self.display.height))
## Config
self.blocks_width = 5
self.aliens_width = 10
self.aliens_height = 4
self.aliens_margin = 2
self.torpedos = []
self.max_speed = 10
self.frame_rate = 25
self.speed_down = 3
self.score = 0
# Build Aliens
self.aliens = self.build_aliens()
# Build Blocks
self.blocks = self.build_blocks()
# Build ship
self.ship = Ship(
logger=self.logger,
display=self.display,
game=self
)
def build_blocks(self):
step = int(self.display.width / self.blocks_width)
blocks = []
start_y = self.display.height - 13
start_x = 0
for x in range(0, self.blocks_width):
block = Block(
logger=self.logger,
display=self.display,
game=self,
x=start_x + x * step,
y=start_y
)
blocks.append(block)
if block:
# Center blocks
offset = (self.blocks_width-1) * step
offset = offset + block.width
offset = self.display.width - offset
offset = offset / 2
for block in blocks:
block.x += offset
return blocks
def build_aliens(self):
# Build level
start_x=2
start_y=1
alien_width = 0
alien_height = 0
aliens = []
for x in range(0, self.aliens_width):
for y in range(0, self.aliens_height):
objAlien = Alien1
if y == 0:
objAlien = Alien2
alien = objAlien(
logger=self.logger,
display=self.display,
game=self,
x=start_x + x * (alien_width + self.aliens_margin),
y=start_y + y * (alien_height + self.aliens_margin),
line=y
)
alien_width = alien.width
alien_height = alien.height
aliens.append(alien)
return aliens
def win(self):
self.display.clear()
self.display.write(
pos=self.display.get_center(you_win),
sprite=you_win
)
#.........这里部分代码省略.........
示例6: print
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import clear [as 别名]
print("Initializing Player")
p = Player(24)
def on_tag_discovered(tag):
# Check if there is a album with this name
try:
selected_album = (join(library_path, f) for f
in listdir(library_path)
if isdir(join(library_path, f))
and bool(re.search(tag + "$", f, re.I))).next()
p.play_album(selected_album)
except StopIteration:
d.draw_text(tag, 12)
p.track_changed += lambda number: d.draw_text(str(number), 40)
p.stopped += lambda: d.clear()
# We have a few buttons
print("Initializing Buttons")
button_prev = Button(17, callback=p.previous)
button_next = Button(27, callback=p.next)
button_pause = Button(18, callback=p.toggle_pause)
button_volup = Button(23, callback=p.volume_up)
button_voldown = Button(22, callback=p.volume_down)
print("Initializing Tag Reader")
tr = TagReader('tty:AMA0:pn532')
tr.tag_discovered += on_tag_discovered
d.clear()
print("Done")