Alphabetic Fridge Magnets / 16-Feb-2009 / 0 comments
This is a small project I initally cooked up a few years back, mainly to prove to potential employers that I can do 'Ajax'. Its still quite a fun project so I thought I would display it here, the code has gone through some quite drastic refactoring over the last couple of years (from no framework to moo-tools to JQuery) so I won't spend to much time focusing on that (but if you want to see how its done you can download the script here)
Inspired by the fridge magnets that I have at home its a kind of guestbook, move the letters around and they stay there for the next visitor to see. The interesting part is a simple algorithm which determines wether you have created an actual word. If you have a little icon appears which shows thesaurus entries for that word.
After each letter move, the algorithm first determines which letters are on a similar horizontal access, we then store these into a separate array. We sort the array from left to right and store the location of our recently moved letter.
From this point in the array we then look left, if there is a letter within a certain distance we add this letter to our potential word. We now add the width of the new letter to the bounds and continue onwards, when eventually we run out of letters or hit a gap that is to large, we return with what we have. Now we do the same to the right hand side, we are left with a potential word.
With our 'word' we send a request to a perl script. This script will store the new location of the letter in the database, and also send an HTTP request to the thesaurus API to see if the word was valid. If it was it is stored in our database and the response is sent back to the browser.
Previously I was using the Thesaurus API provided by Urban Dictionary who unfortunately have stopped provided the service. Now I am using the api provided by Big Huge LABs, although not as fun it does prove the idea. Not all words are supported by the API and the word finding algorithm isn't 100% precise but have a play.

Post new comment