This trick was inspired by Brian Suda who I saw speak at Whisky Web.
- Take a string, any string.
- Hash it using MD5.
- Substring the hash to get a 6-digit hex code.
- Take a look at what colour that hex code represents.
A really simple, really cool way of generating seemingly random colours, that can be used to represent things.
I had a play with this idea and used it to generate a simple flag for any input string:
<?php
$thing = $_GET['thing'];
$md5 = md5($thing);
$col1 = substr($md5, 0, 6);
$col2 = substr($md5, 6, 6);
$col3 = substr($md5, 12, 6);
echo
"<div style='float:left;width:100px;height:200px;background:#{$col1}'></div>\n" .
"<div style='float:left;width:100px;height:200px;background:#{$col2}'></div>\n"
"<div style='float:left;width:100px;height:200px;background:#{$col3}'></div>";
This takes an input string via the GET method variable 'thing' and turns it in to a 3-stripe flag. Examples:
(empty string):
ben
:
bennuttall
:
bennuttall.com
:
The code is on GitHub: github.com/bennuttall/MD5-Flag-Generator/
Check out Brian's book Designing With Data