Simulating traffic lights at an intersection

This is an applet that I wrote for David Bellin's CRC card book.

The applet simulates traffic lights at a 4-way intersection with two left-turn lanes. You can see six sets of traffic lights and sensors (squares next to the traffic lights). Click inside a square to trip the sensor, as an approaching car would. This will cause other traffic lights to turn red (eventually), so that the car can pass.

The code.