Logo for ColdFusion - CFImage Demo

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 X Move the pen forward X pixels.
right x Turn to the right X degrees. Currently X is ignored and all turns are 90 degrees.
left x Turn to the left X degrees. Currently X is ignored and all turns are 90 degrees.
clearscreen/cs Clears the screen.
home Moves the pen to the center of the canvas.
penup/pu Lifts the pen. Any future drawing operations won't be displayed.
pendown/pd Lowers 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.

Archived Comments

Comment 1 by Jim posted on 9/14/2007 at 11:30 PM

I was one of those kids who spent many a n afternoon with other "gifted" kids moving turtles around the screen.

Comment 2 by Shane Zehnder posted on 9/14/2007 at 11:49 PM

Well, at the risk of showing my age and immaturity, one of my first BASIC programs on my Tandy 1000SX was a detailed Teenage Mutant Ninja Turtle all rendered with graphic primitives. Looks like that would be right up my alley. lol

Comment 3 by denny posted on 9/15/2007 at 12:17 AM

I love it, in all of it's glorious dorkishness.

Comment 4 by Dan Vega posted on 9/15/2007 at 12:17 AM

Was one of those kids bald? Did he teach you that you can not bend a spoon, that's impossible. Instead try to understand that there is no spoon.

Comment 5 by Steve Rittler posted on 9/15/2007 at 1:00 AM

Ray, not to ruin your weekend but wouldn't this be pretty cool as an ajax-ified app so you could type in commands and get back an updated image in real time? That would be fun to play with :-)

Comment 6 by Raymond Camden posted on 9/15/2007 at 1:04 AM

Um. Steve. Did you see the last link in the blog entry?

Comment 7 by Steve Rittler posted on 9/15/2007 at 1:06 AM

oh man..in my Master Collection delirium I stopped reading all too soon.

that's it...i'm calling it quits for the week. sorry ray!

Comment 8 by Scott Fitchet posted on 9/16/2007 at 12:30 AM

Sweet demo.

Comment 9 by Matt Davis posted on 9/18/2007 at 6:03 PM

I now work as a CF/Flex developer for the school system where I first used Logo on an Apple IIe. I wonder if they will let me put this on our Intranet...

Comment 10 by Mike Benner posted on 9/25/2007 at 7:24 AM

Yah!!! Now my daughter can start where I started. Ray, Best App Ever!!!!