A long time ago - in a place far, far away (sorry, couldn't resist), I remember seeing a cool little program on the Apple 2c that taught kids programming by having them move a little turtle around a screen. This was based on the Logo programming language. Someone mentioned it on a thread yesterday in CF-TALK, and me being the crazy person I am I decided - what the heck - let me try to recreate this in ColdFusion.

So with that - I present CF_LOGO. This is a custom tag that lets you create a canvas and then issue commands for the turtle (or pen) to draw. For example:

<cf_logo> forward 100 right 90 forward 60 right 90 forward 90 right 90 forward 50 left 90 forward 99 home forward 100 </cf_logo>

This tells the turtle/pen to move, turn, move, etc. The home command simply returns the turtle to the center of the canvas. This creates the following image:

The language supports many operations, but my tag supports the following commands:

forward/fd XMove the pen forward X pixels.
right xTurn to the right X degrees. Currently X is ignored and all turns are 90 degrees.
left xTurn to the left X degrees. Currently X is ignored and all turns are 90 degrees.
clearscreen/csClears the screen.
homeMoves the pen to the center of the canvas.
penup/puLifts the pen. Any future drawing operations won't be displayed.
pendown/pdLowers the pen. Any future drawing operations will be displayed.

The custom tag allows you to specify a height and width, a background and pen color, and you can even tell it to return the image as a CFImage object:

<cf_logo variable="test"> forward 100 right 90 forward 60 right 90 forward 90 </cf_logo>

<cfset imageScaleToFit(test,100,100)> <cfimage action="writetobrowser" source="#test#">

Finally, I've set up a demo that lets you issue commands one at a time, to basically draw a picture online:

http://www.coldfusionjedi.com/demos/logo/test3.cfm

You can download the test files, the demo, and the custom tag below.

And yes - this is a complete and utter waste of time. That's what made it fun.

Download attached file.