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:

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:

A PHP extension to control GPIO on the RaspberryPi – my BrightonPHP talk

A while ago now (back in February!) I did a talk about writing an extension using Zephir to interact with the RaspberryPi’s GPIO.  The extension itself wraps around the wiringPi library and it makes it really easy to write PHP scripts that send output and gather input from the GPIO.

Here are the slides (use left/right arrow keys to navigate):

Full-sized version of the slides

Did you like this? Share it:

phpiwire updated – now with PWM!

I’ve pushed a few changes to phpiwire can now use the PWM functions in wiringPi.  You can use either the hardware PWM pins or any of the GPIOs by using software PWM.  A couple new examples of how to do this have also been added to the repository.

With software PWM comes the requirement to include pthreads, so that’s also linked when you compile the zephir extension.

I’d recommend you do a full clean first before compiling with:

zephir fullclean
zephir install
Did you like this? Share it:

Phpiwire: a PHP extension (written using Zephir) for controlling the Raspberry Pi GPIO

So it’s been a while since my lightening talk on Zephir and I realized I hadn’t really done anything to try to learn it a little more in-depth.  Coincidentally, I was recently going through a drawer and realized that one of my Raspberry Pi’s was in there just begging to be put to some use (seriously, I could practically hear it weep).  So I thought that the only thing to do was to attempt to write an extension using Zephir so that I could control the GPIO via PHP.  I mean, isn’t it obvious? Continue reading “Phpiwire: a PHP extension (written using Zephir) for controlling the Raspberry Pi GPIO”

Did you like this? Share it:

Auto generating basic models for a Zend Framework app

Do you have a database with foreign keys and just wish you could have something automatically create your ZF models from it? Well, today that was me. So as a little proof of concept, this is the code I came up with to do it for me…

But before we get to that, a few caveats:

  • It’s just a proof of concept
  • The output needs updating for proper reference names, etc.
  • Outputs everything to screen in one go and doesn’t save the files.

However, it might be handy to someone, so I post it up for your comments.
Continue reading “Auto generating basic models for a Zend Framework app”

Did you like this? Share it:

Slider – part 2 – using a mouse wheel

Following on from the previous post, I thought it’d be nice to have the handle move on a mouse wheel. Looking around for mouse wheel integration, it seems that it’s only a short amount of code to update Prototype to use the mouse wheel. Why it’s not in the core code I don’t know, as it seems rather handy. The mouse wheel code is listed at the Prototype Event Extension article over at Ajaxian.

Continue reading “Slider – part 2 – using a mouse wheel”

Did you like this? Share it:

Scriptaculous slider trick

Yesterday I was looking at the Scriptaculous library, in particular the slider bar. I had used it once before with some success, using a graphic for the track and gripper. But that’s was boring! What I wanted was to see the bar fill up with colour when it was slid. Something like this:

Slider demo

I hadn’t seen anything like this around (not saying it hasn’t been done, just that I hadn’t seen it!), so after a bit of playing I found out it was actually very easy to create. And this is how I did it…

Continue reading “Scriptaculous slider trick”

Did you like this? Share it: