Four-Way Traffic Simulation

Observe how vehicles arriving from four directions move through an intersection controlled by rotating traffic lights. Cars appear at random intervals, and the green light changes to the next direction approximately every 5–7 seconds.

Active green: North · Cars: 0

How the Simulation Works

Each traffic light represents one direction: north, east, south, or west. Only one direction has a green light at a time, while the other three remain red.

  • The green phase rotates clockwise every 5–7 seconds.
  • Vehicles appear at random intervals of roughly 1–5 seconds.
  • Cars move when their direction has a green light.
  • Once a car enters the intersection, it continues until it leaves the crossing.
  • Pause stops or resumes the simulation.
  • Reset removes all cars and restores North as the first green direction.
  • Add Car immediately creates a vehicle from a random direction.