Traffic Lights

Drawing Traffic Lights With Perl

For a thing (that you may hear more about at some point in the future) I needed diagrams of traffic lights. But Google Image Search didn’t really have what I was looking for. Everything was either too realistic or not CC-licensed so I couldn’t use the images how I wanted.

So I decided to do it myself. But I’m not exactly artistic. I far prefer it when I can get computers to draw images for me. I’ve dabbled with SVG before and it seemed like the perfect tool for the job. And there’s a module from CPAN that makes it simple to create SVG images from Perl.

It only took an hour or so before I was drawing images like the one above – which was exactly what I was looking for.

Initially, I shared my code as a Gist, but since then I’ve extracted the useful bits into a module which I’ve uploaded to CPAN asย SVG::TrafficLight.ย I’ve tried to make it as configurable as possible, so you should be able to use it for all your traffic light drawing needs as well.

Starting to use it is pretty simple.

The default sequence of lights shows the UK’s standard traffic light sequence (green, ย amber, red, red and amber, green) but it’s simple enough to produce a different sequence (even one that you would never see on the roads).

If you read the documentation, you’ll see how you can customise pretty much anything in the diagram – the size of the lights, the padding between them, even the colours used.

Let me know if you find it all at useful. SVG is fun. I’ll think I’ll investigate it some more.

 


Also published on Medium.


Posted

in

by

Comments

3 responses to “Drawing Traffic Lights With Perl”

  1. zentara Avatar

    Nice site Dave. I finally understand how Dancer works.

  2. onefloid Avatar
    onefloid

    Thanks Dave. The traffic lights looks nice.

  3. kamaksha Avatar
    kamaksha

    can you please help me with traffic light coding in perl graphics. As i am totally a new user to it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.