An open API service indexing awesome lists of open source software.

https://github.com/willkirkmanm/traffic

Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules
https://github.com/willkirkmanm/traffic

parsonlabs simulation traffix

Last synced: about 1 year ago
JSON representation

Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules

Awesome Lists containing this project

README

          




Traffic



Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules

## Features

- **Intersection with Traffic Lights**: Four-way intersection with coordinated traffic lights
- **Vehicle AI**: Vehicles that react to traffic lights and avoid collisions
- **Realistic Movement**: Vehicles accelerate, decelerate, and stop based on traffic conditions
- **Visual Feedback**: Color-coded traffic lights and directional vehicles

## Traffic Light Algorithm

The simulation implements a simple time-based traffic light algorithm:

1. **Coordination**: East-west and north-south lights are coordinated to avoid conflicts
2. **Cycle**: Each light cycles through Red (5s) → Green (5s) → Yellow (2s) → Red
3. **Priority**: When east-west lights are green, north-south lights are red and vice versa

## Vehicle Behavior

Vehicles in the simulation exhibit several intelligent behaviors:

- Stop at red and yellow traffic lights
- Maintain safe distances from other vehicles
- Accelerate when the path is clear
- Travel at different speeds (randomized for each vehicle)
- Automatically despawn when out of view

## Running the Simulation

### Prerequisites

- Rust and Cargo (1.39 or newer)

### Installation

1. Clone this repository
```bash
git clone https://github.com/WillKirkmanM/traffic.git
```

2. Build and run:

```bash
cargo build --release
cargo run --release
```