Overview
Example script that provides a 2D top-down map visualization of the CARLA simulation using pygame, supporting both spectator and hero vehicle modes with full keyboard controls.
Description
This script (no_rendering_mode.py, 1618 lines) implements a comprehensive 2D map visualizer as an alternative to the 3D rendering viewport. It uses pygame to render a top-down view of the CARLA world, displaying vehicles, walkers, traffic lights, roads, sidewalks, and other map elements using the Tango Desktop Project color palette. The visualizer supports two modes: map mode (free camera with mouse drag/zoom) and hero mode (camera following a controlled vehicle with keyboard input). Keyboard controls include W/S/A/D for driving, Q for reverse, Space for handbrake, P for autopilot, M for manual transmission, TAB to toggle hero mode, F1 for HUD, I for actor IDs, and ESC to quit. The script imports from carla.TrafficLightState for rendering traffic light colors and uses weakref for safe actor references. The extensive color constant system uses semantic naming (COLOR_BUTTER, COLOR_ORANGE, COLOR_CHAMELEON, COLOR_SKY_BLUE, COLOR_PLUM, COLOR_SCARLET_RED, COLOR_ALUMINIUM) with 3 brightness levels each.
Usage
Use this example for lightweight simulation monitoring without GPU rendering overhead, for recording top-down views of traffic scenarios, or as a reference implementation for custom 2D CARLA visualizers.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/examples/no_rendering_mode.py
Signature
# Color palette using Tango Desktop Project scheme
COLOR_BUTTER_0 = pygame.Color(252, 233, 79)
COLOR_ORANGE_0 = pygame.Color(252, 175, 62)
COLOR_CHAMELEON_0 = pygame.Color(138, 226, 52)
COLOR_SKY_BLUE_0 = pygame.Color(114, 159, 207)
COLOR_PLUM_0 = pygame.Color(173, 127, 168)
COLOR_SCARLET_RED_0 = pygame.Color(239, 41, 41)
COLOR_ALUMINIUM_0 = pygame.Color(238, 238, 236)
# ... 3 brightness levels per color
# Keyboard controls:
# TAB: toggle hero mode | W/S: throttle/brake
# A/D: steer | Q: reverse | Space: handbrake
# P: autopilot | M: manual transmission
# F1: toggle HUD | I: actor IDs | ESC: quit
Import
# Run as a command-line tool:
python no_rendering_mode.py
# Requires: pygame
I/O Contract
| Input |
Type |
Description
|
| CARLA simulation |
Server connection |
Running CARLA server
|
| Keyboard input |
pygame events |
Vehicle control and mode toggling
|
| Mouse input |
pygame events |
Map drag and zoom (map mode)
|
| Output |
Type |
Description
|
| Pygame window |
2D display |
Top-down map view with actors
|
| HUD overlay |
Text display |
Speed, location, map info
|
| Visual Element |
Color |
Description
|
| Vehicles |
Sky Blue |
Vehicle actor positions and orientations
|
| Walkers |
Orange |
Pedestrian positions
|
| Traffic Lights (Green) |
Chameleon |
Active green lights
|
| Traffic Lights (Red) |
Scarlet Red |
Active red lights
|
| Traffic Lights (Yellow) |
Butter |
Active yellow lights
|
| Roads |
Aluminium dark |
Road surfaces
|
| Sidewalks |
Aluminium light |
Sidewalk surfaces
|
Usage Examples
# Launch 2D visualizer
python no_rendering_mode.py
# With specific server connection
python no_rendering_mode.py --host 192.168.1.100 -p 2000
# The script provides a complete pygame-based 2D rendering:
# 1. Connects to CARLA
# 2. Retrieves map topology and actor positions
# 3. Renders top-down view using pygame
# 4. Supports hero mode for driving with keyboard
# 5. Mouse wheel zoom, drag to pan in map mode
Related Pages