Sail the Virtual Seas in 3D
One of the really cool things about Processing is that it allows easier coding of 3D scenes that enable you to create some fun interactive graphics. This is mostly down to the combination of the P3D graphics library and the draw() function which handles timed redrawing of scenes. By changing a few variables between each redraw (such as the position of a boat, or the storminess of the sea), we can quickly and easily create a virtual seascape on which to sail a small boat. If you don't believe it (and who in their right mind would ;-) below is an applet version to prove it. Simply use your left and right arrow keys to steer the boat, the up and down arrow keys to change the storminess of the sea, and the number keys (0 to 9) to change the speed of the boat.
The code (which you can download by clicking here) is relatively simple, most of the lines going into creating the 3D shapes. The boat itself is the most complex function, but only because it is formed from triangles, with each vertex taking one line of code. I've also used the code with an Arduino to control the boat and storminess, just using potentiometers. If you read the virtual puppet page (under Arduino in the menu over on the left of this page), you should also be able to set up your own microcontroller controlled boat sailing project fairly simply.
You may find that the applet runs a little slowly if you are using an old computer, or even on a netbook. That's because it essentially creates a completely new sinusoidal seascape, with boat and bouys, numerous times per second. It was written and tested on a netbook with an Intel Atom processor, on which it worked much more smoothly under Linux. However, if you have a more powerful computer you could quite easily add a second boat and have a race!