JavaScript
$(function() {
traffic_lights = [
[{color:'green' ,time:9 },
{color:'yellow' ,time:6 },
{color:'red' ,time:19 },],
[{color:'green' ,time:9 },
{color:'yellow' ,time:6 },
{color:'red' ,time:19 },],
[{color:'green',time:30},
{color:'yellow',time:6},
{color:'red',time:17},],
[{color:'green',time:30},
{color:'yellow',time:6},
{color:'red',time:17},],
[{color:'red',time:29},
{color:'yellow',time:6},
{color:'red',time:27},],
[{color:'red',time:29},
{color:'yellow',time:6},
{color:'red',time:27},],
[{color:'green',time:32},
{color:'yellow',time:6},
{color:'red',time:40},],
[{color:'green',time:32},
{color:'yellow',time:6},
{color:'red',time:40},],
[{color:'green',time:37},
{color:'yellow',time:6},
{color:'red',time:33},],
[{color:'green',time:37},
{color:'yellow',time:6},
{color:'red',time:33},],
[{color:'red',time:23},
{color:'yellow',time:3},
{color:'green',time:80},
{color:'yellow',time:6},],
[{color:'gray',time:26},
{color:'green',time:46},
{color:'gray',time:40},],
[{color:'red',time:56},
{color:'yellow',time:3},
{color:'green',time:21},
{color:'yellow',time:6},],
]
for (var a = 0, f; a < traffic_lights.length; a++) {
var g = traffic_lights[a];
f = $("#c" + a);
(function (a, d) {
var b = 0,
time = 0;
return function s() {
time || (a.css({"background-color": d[b].color}), time = d[b].time, b = ++b % d.length);
a.html(time);
time--;
window.setTimeout(s, 1e3);
}
})(f, g)();
}
})