Skip to content

an2n/midnight-transit

Repository files navigation

Midnight Transit

A retro traffic light simulation built with R3F and XState. Watch cars stop for pedestrians, emergency vehicles override the system, and enjoy the synthwave aesthetics.

Midnight Transit Demo

Midnight transit preview (low quality)

Tech Stack

Technology Purpose
React UI framework
TypeScript Type-safe JavaScript
Vite Build tool and dev server
React Three Fiber (R3F) React renderer for Three.js
Three.js 3D graphics library
@react-three/drei Useful helpers for R3F
@react-three/cannon Physics engine integration
@react-three/postprocessing Post-processing effects (bloom, vignette, noise)
XState State machine library for traffic logic
Biome Linting and formatting

Vibe Coded With

Tool Purpose
GitHub Copilot AI pair programming
Claude Opus 4.5 AI assistant

XState Machine Visualizer

The traffic light logic is powered by an XState state machine. You can visualize and interact with the machine below:

Traffic Light System State Machine

View in Stately Editor →

Machine Overview

The traffic system uses a parallel state machine with two concurrent states:

trafficLightSystem (parallel)
├── carLight
│   ├── green         → Cars can go
│   ├── greenWaiting  → Waiting before pedestrian crossing
│   ├── yellow        → Prepare to stop
│   ├── red           → Cars must stop
│   ├── redWaiting    → Brief pause before resuming
│   └── yellowToGreen → Prepare to go
│
└── pedestrianLight
    ├── dontWalk      → Pedestrians must wait
    ├── waitingToWalk → Signal transitioning
    ├── walk          → Safe to cross
    └── flashing      → Finish crossing soon

Events

Event Description
pedestrian_button Pedestrian requests to cross
emergency Emergency vehicle triggers override
clear_emergency Emergency mode ends

Getting Started

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm

Installation

# Clone the repository
git clone https://github.com/yourusername/midnight-transit.git
cd midnight-transit

# Install dependencies
pnpm install

# Start development server
pnpm dev

Available Scripts

Command Description
pnpm dev Start development server
pnpm build Build for production
pnpm preview Preview production build
pnpm lint Lint and fix with Biome
pnpm format Format code with Biome

License

MIT

About

A retro traffic simulation with R3F and XState state machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors