Napili - a Turtle Graphics program with JavaFX and Groovy
My very first programming language was BASIC. But the first time I ever thought I could do this for a living was when I discovered LOGO. While the language itself didn't interest me in particular, I was fascinated by Turtle Graphics.
If you're unfamiliar with Turtle Graphics, it's a pretty simple concept: while traditional graphics paradigms involve an x/y coordinate system, where each pixel is filled in based on it's coordinate location, and all functionality is built around coordinates, turtle graphics systems instead work with a two objects: a drawing surface, whose properties are opaque to the programmer (except possibly it's size), and a turtle, which is the object the programmer manipulates. The Turtle is, in turn, an abstraction - it has a location, an orientation, and a pen. The pen, in turn, has attributes such as color, width, and up verses down. The turtle is usually represented on the screen by either a triangle, a diamond, or a bitmap of a cartoon turtle.
The turtle is controlled via commands, such as PEN DOWN, FORWARD 100, and RIGHT 45 (which sets the pen to draw, moves forward by 100 arbitrary units, and turns the turtle 45 degrees clockwise).
This is a great example of a DSL for our purposes, since it's a very specific domain (drawing via a turtle), is a very well understood paradigm, and would benefit greatly from the control structures that Groovy gives us.
At the same time that I was thinking about what kinds of programs to use for my examples, I attended the GR8US conference, and several speakers sang the praises of JavaFX, which had just been released as part of the JDK. So, I thought, why not learn about JavaFX while creating this Groovy Turtle Graphics program? Scala already has the excellent Kojo, but I couldn't find something similar for Groovy, so, why not?
The result is Napili, now available on GitHub under the Apache License.
Over the next few posts in my main blog, I'll go over how I applied my previous posts on DSLs to the problem of creating a Turtle Graphics DSL. I'll also use this program to cover a few other topics that I have planned, such as program throttling and security.
In the interim, if you're interested in a small, simple example of a DSL (or, for that matter, of JavaFX animations), download it and check it out.
One last note: Napili isn't really ready to indoctrinate some new high school kid into the world of Groovy programming. In particular, it's "editor" is just a text area, not some spiffy syntax highlighting full featured component, and it's error reporting is very, very primitive. If you think that the world really needs a Groovy turtle graphics programming IDE, please drop me a line and let me know. Bonus points if you want to help.