Sometimes football TV pundits talk about “the Premier League race” as though it were an actual race between the teams, rather than just a list of teams sorted in descending order of points. I thought it would be interesting to see what a Premier League season would look like if it actually was a race, so I decided to make a little animation. This post is a write up of how I did this. If you want to go straight to the animation for the 2011-2012 season you can do so.
The data I used comes from football-data.co.uk. They have free CSV files containing all the match results for the English Premier League (and many other European leagues) going back to 1993-1994.
I used another PHP script to generate the images for each team. This uses the PHP functions imagecreate and imagefilledrectangle to draw the appropriate shirt pattern and colours for each team. I can then automatically generate the team images with code like:
GenerateImage('west-ham', $properties, "sleeves", "#7F0000", "#80BFFF");
GenerateImage('wigan', $properties, "stripes", "#236BD8", "#FFFFFF");
GenerateImage('wimbledon', $properties, "solid", "#000066");
This makes adding new teams really easy; I just add a line to my script for each team. This was the most fun part of this project. There is something very satisfying about running a script and seeing it generate a folder full of images automatically.
I added buttons to pause and restart the animation at any time, and a date control to allow you to select a date and view the state of the race on that date.