Turtle Graphics in Groovy

download Turtle Graphics in Groovy

If you can't read please download the document

description

Using DSL techniques to recreate the children's learning tool

Transcript of Turtle Graphics in Groovy

  • 1. Turtle Graphics in Groovy Jim Driscoll

2. 2 My Background ADFm Part of Oracle's ADF Framework Provides data binding and database access Provides ways to customize data views via Groovy Groovy uses have basic DSL customizations Wanted to Learn JavaFX (after last year's GR8 Conf) Have 5 year old daughter Napili named after the Maui bay 3. 3 Logo An early programming language (1960's) Popular in the 80's as a teaching tool Which is how I first heard about it A dialect of Lisp (but much more approachable) Currently (per Wikipedia) 197 different dialects Most famous for it's use of Turtle Graphics 4. 4 Turtle Graphics Vector based graphics using a relative cursor The Turtle Represented in early work as a triangle Turtles have three attributes A location An orientation A pen (which has on/off state, color, width, etc) 5. 5 Turtle Commands home left / right (takes int arg, degrees) forward / back (takes int arg, #pixels) penup / pendown pencolor (takes Color arg) show / hide speed (takes int arg) 6. 6 Language Style Commands without parens left 90, home, hide, etc Chained Commands left 90 forward 100 hide (as one line) Use with an explicit turtle, or with an implicit turtle Use Groovy language constructs Define variables Define methods Closures 7. 7 Language Decisions DSL vs GPL DSL (Domain Specific Language) A limited language, designed to be useful for a specific task HTML, SQL, stuff you can build with Groovy Builders GPL (General Purpose Language) A general language, designed to be useful for any task Java, Groovy, Assembler, etc I went the GPLish route, full Groovy + DSL extensions But there's not necessarily a one right answer 8. 8 Demo 9. 9 First, Create a Framework Created a Turtle class, with supporting classes Methods like #home(), #hide(), #forward(int), etc. Allows drawing on a canvas via a turtle Used JavaFX, including animations This isn't a JavaFX talk... Once that's all working, add the control language 10. 10 Executing Programs In Memory Object GroovyShell#evaluate(String) Can be slow (10ms) Cacheing Scripts Script GroovyShell#parse(String) slow part (10ms) Object Script#run() fast part (