This is a collection of some of my javascript-centric code snippets. Some have a practical purpose, while some are for demonstration purposes. Many of them were written "just for fun".

Please feel free to try out any of the snippets below - that is why they are here. If you find any of the code useful, you are more than welcome to use it, but please acknowledge its origin.

Note: All of the snippets require JavaScript to be enabled before they will run.

Twenty line JavaScript competition entries

Every month, the people in the DHTML/Javascript forum over at the OZONE Asylum hold a 20-line JavaScript competition. Whilst the object is to keep the entries under 20 lines of code, it's just a bit of fun -- so the 20-line rule isn't strictly enforced. The prize is to set the challenge for the next month's competition. Here are some of my entries.

July 2005 - Creative writing with text

Visit the July 2005 competition thread at the OZONE Asylum

The goal: To do something creative with text.

I decided to work on a horizonatal text scroller that had a nice deceleration and fad effect. Once I had achived the ability to place multiple of these tickers on the page, I looked at scraping some news sites to provide some vaguely useful content (I even managed to make the headlines clickable). Overlaying them all over an montage of news images (initially static) adds a certain visual appeal.

April 2005 - Sliding puzzle game

Visit the April 2005 competition thread at the OZONE Asylum

The goal: To make a sliding puzzle - with an "interesting twist".

I decided to code a classic 3 x 4 sliding puzzle and add in a random choice of images each game. The trick was writing a randomising routine that yeilded solvable puzzles. This was all managed within the 20-line rule.

February 2005 - Night-time at the Zoo

Visit the February 2005 competition thread at the OZONE Asylum

The goal: To make a zoo, whether it holds static or animated animals, or even a real zoo where you feed the animals.

I wanted to create something that mimiced an old screen saver I had once seen on the Apple® MacPlus in the late 80's. The code is designed to fill the screen with a night time scene, and different sets of eyes open and close to the background sound of crickets and night noise. The javascript keeps the whole thing random (and to a degree extensible) and remains within the 20-line limit.

Mathematical Problem Solving/AI

This section contains some more cerebral javascript. From time to time I have the opportunity to look at utilising Javascript in some fun ways. The following examples focus on mathematical problem solving using logic (rather than trial-and-error) and Artificial "Intelligence".

May 2005 - Su Doku puzzle solver

Visit the official Su Doku web site

The goal: To look into various ways of solving Su Doku puzzles using logic.

I created this code as I learned the various ways to solve the Su Doku mathematical puzzles that appear regularly in newspapers and online.

The demonstration page has three "hard coded" puzzles -- and you can use the page merely to record your own solutions... but you can also get the puzzles solved. All except the last one... that one gets stuck and I'm still working on a logical way to move on.

2004 - Plunder the Prize javascript game (Safari only)

The goal: create some kind of game that utilised artificial intelligence as a part of game play.

This simple game uses AI to control the "bad guys" whilst you run around trying to "Plunder the Prize". There are several levels to the game as well. There is also a simple game world editor that allows you to graphically create levels. I have built the code to easily editable and extensible should anyone want to take the time.