Genetic Algorithms and the Mona Lisa

Way back when I was at university (way, way, waaay back) I did some Artificial Intelligence stuff; genetic algorithms, neural networks, and the like. Honestly, though, I really don’t remember much (any!) of it, though I do remember enjoying the genetic algorithms side of things.

I haven’t thought about that kind of thing for quite some time, but the other day while look for something else entirely, I came across a program called EvoLisa. It was written in 2008, but it intrigued me. The program was trying to create a version of the Mona Lisa using a genetic algorithm to ‘evolve’ polygons so that they become fitter and therefor look more like the Mona Lisa. It was written in .Net, but I liked the look of it and wanted to see if I could convert it to run using Javascript and the canvas tag to show the image.

The code

I converted the program and also added using quadratic and bezier curves in order to try to smooth out the image a bit, and I think the results are quite good. I’ve put my code up on GitHub, so feel free to fork and improve!

example output

Did you like this? Share it:

WCAG colour checker

About five years ago I created a small PHP class that would check the contrast of a foreground and background colour and give a report on whether it was accessible in accordance with the WCAG recommendations (so either AA or AAA compliant).

I’ve recently had cause to dig out that script which gave me the opportunity to also create a version in javascript.

Usage is very simple… Say I have these two colours:

vivid red – rgb(207, 46, 46) – #cf2e2e


cyan blueish grey – rgb(171, 184, 195) – #abb8c3

If I used then in combination, with say the red being the background colour and the grey being the text colour, the PHP code would look something like:

var_dump(WCAG::accessibility('abb8c3', 'cf2e2e'));

The result of which would show the contrast ration and if it passes WCAG 2.0 for AA, AA with large fonts, AAA, and AAA with large fonts… No surprise really that the combination above would fail!

array(2) {
'ratio' => string(4) "2.54"
'2.0' => array(4) {
'aa' => bool(false)
'aa-18pt' => bool(false)
'aaa' => bool(false)
'aaa-18pt' => bool(false)

But try that with the red background and white text and we’d see a different result:

// var_dump(WCAG::accessibility('fff', [207, 46, 46]));

array(2) {
'ratio' => string(4) "5.14"
'2.0' => array(4) {
'aa' => bool(true)
'aa-18pt' => bool(true)
'aaa' => bool(false)
'aaa-18pt' => bool(true)

You can supply the colours in full or short hex format – with or without the # – or as a RGB array.

The javascript version is just as simple to use. So why not check out the repository with the code, fork is and contribute if you’d like – examples are included in the repo.

Did you like this? Share it:

First attempt at a kiridashi

A kiridashi is a small Japanese knife with a chisel grind and sharp point and it used as a utility knife, scoring or carving.

I had some really rusty angle iron kicking around still, so I thought I’d get in a little practice. Unfortunately I still have no forge, so couldn’t try to smith the shape so I went with stock removal – it was good practice on using the angle grinder and hand sanding the

Now, this probably isn’t great metal for making a knife – it’s certainly quite thing and probably doesn’t have enough carbon to hold an edge (and I’m not very adept yet at the ol’ spark test to really be able to tell), but I’m pretty happy with the result (even if it didn’t hold it’s edge for too long!)

Did you like this? Share it:

I forged a necklace (2.0)

Had a bit of cut off metal while I was practising drawing down some round stock, and my daughter also asked for a “swirly type necklace”. So I attempted to make another couple necklaces…

I personally really like the simple pendant; it’s a little bit rounded on the top, angular on the sides, and it feels quite nice.

I’d like to practise making some more of these types of things – I saw a beautiful damascus (pattern welded) steel pendant once and would love to attempt something similar… This’ll do for now, though!

Did you like this? Share it:

Homemade headphone hook

Sometimes it’s nice to get out from in front of the monitor and coding and make something in the garage.

One thing I really wanted was a headphone stand because I was tired of leaving my headphones on my desk only for the darned things to get in the way. But then it struck me; I am trying to learn a few blacksmithing techniques so why not just make something?!

Oh yeah, that’s right, my homemade forge broke and I haven’t fixed it yet.

But, wait a moment… I have a blow torch, an angle grinder, and some really rusty angle iron from when I tore down my old and knackered garage door. Surely I can do something with that, right?… Right?

Turns out that, yes. Yes, I can!

OK, not the snazziest thing in the world, but it fits my needs absolutely perfectly, has a nice ‘rustic’ look to it, and is ideal for my HyperX headset.

Did you like this? Share it:

Simple Halloween prop

OK, so it looks like I haven’t done anything for ages, but I have, I promise! It’s just that I suck at remembering to post about it after, even though I have all the best intentions to do so. Intentions will only take you so far, though, so let’s get on with a post of something that was whipped up for Halloween.

Blinky, the super easy Halloween prop

For Halloween we had an idea to have eyes in the hedges that would glow and blink so that the trick-or-treaters would feel watched. We had to make this on a super-low budget and we don’t have anything fancy like a 3D printer (I’m open to donations if anyone wants to give me their old 3D printer… just sayin’!) The result (apologies for the shoddy camera work) looks something like this:

And here’s how it was made…

Continue reading “Simple Halloween prop”
Did you like this? Share it:

Git and Windows; file path too long – fix!

I ran into an issue today with Git and Windows… I was trying to do a pull from a repo and it kept failing because one of the file paths was too long. Very frustrating!

Thankfully there was a simple fix; just running this from the shell:

git config --system core.longpaths true

Did you like this? Share it:

I forged a necklace

Made this necklace for my better half. It was the first thing I forged on my bbq-forge and it came out not too bad. I had to dress my hammer after as I was leaving too many cuts in the metal (though that has a lot to do with my inexperience!), which worked a treat! Kind of wish I had done that before trying to forge the necklace, but oh well.

Did you like this? Share it:

Filter an array of objects

Quite often I might have an array of objects, be it from a db query or some json object, and I want to filter that list in a particular way.  Lots of times I would find myself doing the same old thing; creating a new array, looping and looping until all I had left was what matched my filter.

I’m sure you’ve been there and done it a thousand times, too.

Well, this little function should help that task out a lot!

Say I had an array of people objects and wanted only those people who’s name was Bob and was aged 35, I could do something as simple as:

$filtered = ofilter($items, ['name' => 'Bob', 'age' => 35]);

Or maybe something a little tricker; I wanted to get anyone whose age was between 18 and 35 (inclusive):

$filtered = ofilter($items, ['age' => function($age) { return ($age >= 18 && $age < = 35); }]);

Pretty easy, eh?

Here’s the code – it’s a GitHub gist, so feel free to fork and improve!
Continue reading “Filter an array of objects”

Did you like this? Share it: