A Simple Traffic Simulator

There are four types of cars on the road: trucks (gray), sedans (navy blue), SUVs (light blue) and sports (red). They follow simple rules as to when to speed up, slow down or break hard. They differ in their passenger capacity and maximum speed. Each car has a driver and a random number of passengers up to capacity. Those are marked as little squares. Each car displays its current speed in a bubble behind it. When it hits the breaks the bubble turns red. Before a car enters the road its plate, serial number and the identity of its driver and passengers are revealed.
This is an example of Object Oriented Programing with Ruby. The driver and passengers are objects, instances of the Person class. Each car on the road is an object, an instance of a subclass, either Truck, Sport, Sedan or SUV that inherits from the Car class. A simulation object, instance of the Sim class, controls the cars on each road. The simulation is set as a Sinatra app running on Heroku. The Simulation is stepped forward with http requests. These requests, to a top and bottom routes return a JSON. The JSON represents the state of the simulated objects at that point in time. An HTML/CSS/JavaScript UI renders and refreshes the cars and info for each road.
Made by Ron Ilan (2017)
0
0
0
0