First setup
This commit is contained in:
parent
d8247fa21d
commit
93b83bad21
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma de
|
||||
# Barcelona (UAB).
|
||||
#
|
||||
# This work is licensed under the terms of the MIT license.
|
||||
# For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
# Allows visualising a 2D map generated by vehicles.
|
||||
|
||||
"""
|
||||
Welcome to CARLA map visualizer
|
||||
|
||||
ESC : quit
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
try:
|
||||
import pygame
|
||||
from pygame.locals import K_DOWN
|
||||
from pygame.locals import K_LEFT
|
||||
from pygame.locals import K_RIGHT
|
||||
from pygame.locals import K_UP
|
||||
from pygame.locals import K_ESCAPE
|
||||
except ImportError:
|
||||
raise RuntimeError('cannot import pygame, make sure pygame package is installed')
|
||||
|
||||
# Handles keyboard and mouse input
|
||||
|
||||
|
||||
class KeyboardInput(object):
|
||||
|
||||
def _parse_events(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
elif event.type == pygame.KEYUP:
|
||||
# Quick actions
|
||||
if event.key == K_ESCAPE:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
def _parse_keys(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
# if keys[pygame.K_LEFT]:
|
||||
# Do something
|
||||
|
||||
def parse_input(self):
|
||||
self._parse_events()
|
||||
self._parse_keys()
|
||||
|
||||
|
||||
def game_loop(args):
|
||||
|
||||
# Init PyGame and classes
|
||||
pygame.init()
|
||||
keyboard = KeyboardInput()
|
||||
|
||||
try:
|
||||
display = pygame.display.set_mode((args.width, args.height))
|
||||
pygame.display.set_caption(args.description)
|
||||
|
||||
while True:
|
||||
keyboard.parse_input()
|
||||
|
||||
display.fill((0, 0, 0))
|
||||
pygame.display.update()
|
||||
|
||||
finally:
|
||||
pygame.quit()
|
||||
|
||||
|
||||
def main():
|
||||
# Parse arguments
|
||||
argparser = argparse.ArgumentParser(
|
||||
description='CARLA No Rendering Mode Visualizer')
|
||||
print (argparser.description)
|
||||
argparser.add_argument(
|
||||
'--res',
|
||||
metavar='WIDTHxHEIGHT',
|
||||
default='1280x720',
|
||||
help='window resolution (default: 1280x720)')
|
||||
|
||||
args = argparser.parse_args()
|
||||
args.description = argparser.description
|
||||
args.width, args.height = [int(x) for x in args.res.split('x')]
|
||||
|
||||
# Call game_loop
|
||||
try:
|
||||
game_loop(args)
|
||||
except KeyboardInterrupt:
|
||||
print('\nCancelled by user. Bye!')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue