For some time, I’ve been fascinated with github identicons.
It’s quite easy to see why:
As you can see, they’re very distinctive, and even kinda pretty, despite being extremely simplistic.
A while back, I worked on a chat bot project with a friend. Despite it having been 2 years since that, I can still remember their identicon as purple and looking a bit like the head of an animal.
It’s honestly quite surprising that I can remember a seemingly obscure icon from that long ago and not remember what time I woke up this morning or what I ate for breakfast.
I’m not an artist, but I imagine that identicons are good at their job because of the creation of complex shapes, which as humans, we are very good at automatically recognising and ascribing meaning to. Even if they’re meaningless. With the addition of colours, a single icon can become clearly recognizable.
So how are these icons actually generated? It turns out to be quite easy.
- Create an empty grid (5x5).
- Pick a random colour.
- Iterate over half the grid and optionally fill a square.
- If you do, also generate another square for the other side of the grid.
- Output all the squares in some neat format.
As you can note, this algorithm only requires some output, loops, conditionals, some string formatting and a little sprinkling of random number generation.
This makes it quite an interesting little project to implement when learning a new language. If you start out with knowing nothing about a language, by the end you’ll know how to write most of the basic programs that you’ll need.
So, if you’re looking for a neat project to start learning a new language, I would highly recommned trying to make some identicons. And, they’re quite fun to show off to other people as well!
Here are my personal recommendations for doing it:
- Create the identicons using svg. This is really easy to do because you just need to write it to stdout and then redirect it to a file. No need to mess around with png libraries or HTML5 canvas.
- Allow passing a seed over stdin or through argv.
- Make it flexible - don’t just hardcode in magic numbers, instead use constants, or, even better let the user modify them.
- Don’t just rush through building it, spend time researching the language’s best practices.
Hopefully I’ve convinced you a bit about the glory of identicons. If so, you might be interested in my various collection of implementations in different languages on github.
If you’re interested in reading more about identicons and the different types that exist, you can read more about it here.