[racket] New turtle graphics package + a few questions

144 views
Skip to first unread message

Daniel Prager

unread,
Feb 19, 2013, 6:00:24 AM2/19/13
to us...@racket-lang.org
I've written an interactive turtle graphics package, complete with
animated turtle imagery, aimed at Dr Racket using parents with elementary-school aged kids.



I'd appreciate tips in a couple of areas:

1. Code organization:
 
At the moment everything is dumped in one directory.  My problem is that when I put -- for example -- an example in an /examples subdirectory and (require "../turtle-graphics.rkt") the line 

(define *turtle-image* (read-bitmap "turtle.png"))

in turtle-graphics.rkt treats the subdirectory as the current directory rather than the parent directory, giving a file not found directory.

2. How do I turn an image built up from (empty-scene ...) into a bitmap% ?  I want to use (write-animated-gif ...) to make a few animated gifs to spruce up my documentation.

Finally, is this the kind of thing that would be worth putting up on PLaneT straight-away, or better to mature it a bit on github?


Thanks 

Dan

Sam Tobin-Hochstadt

unread,
Feb 19, 2013, 8:13:11 AM2/19/13
to Daniel Prager, users
On Tue, Feb 19, 2013 at 6:00 AM, Daniel Prager
<daniel....@gmail.com> wrote:
>
>
> 1. Code organization:
>
> At the moment everything is dumped in one directory. My problem is that when I put -- for example -- an example in an /examples subdirectory and (require "../turtle-graphics.rkt") the line
>
> (define *turtle-image* (read-bitmap "turtle.png"))
>
> in turtle-graphics.rkt treats the subdirectory as the current directory rather than the parent directory, giving a file not found directory.

You want to use `define-runtime-path` here.

Sam
____________________
Racket Users list:
http://lists.racket-lang.org/users

Matthias Felleisen

unread,
Feb 19, 2013, 9:07:35 AM2/19/13
to Daniel Prager, us...@racket-lang.org

On Feb 19, 2013, at 6:00 AM, Daniel Prager wrote:

> I've written an interactive turtle graphics package, complete with
> animated turtle imagery, aimed at Dr Racket using parents with elementary-school aged kids.



Thanks, that's great. In what way did you find the existing one lacking?


> 1. Code organization:


As Sam said.



> 2. How do I turn an image built up from (empty-scene ...) into a bitmap% ? I want to use (write-animated-gif ...) to make a few animated gifs to spruce up my documentation.

#lang racket/gui

(require 2htdp/image mrlib/gif)

(define width 100)
(define height 80)

(define image
(overlay
(rectangle (- width 10) (- height 10) 'solid 'red)
(rectangle width height 'solid 'blue)))

image

(define bm (make-object bitmap% width height))
(define dc (make-object bitmap-dc% bm))
(send dc clear)
(send image draw dc 0 0 0 0 width height 0 0 #f)

(define file "/tmp/foo.gif")
(when (file-exists? file) (delete-file file))

(write-animated-gif (list bm bm) 5 file)



> Finally, is this the kind of thing that would be worth putting up on PLaneT straight-away, or better to mature it a bit on github?


Consider keeping it on github and turning it into a Planet2 package (beta) instead of Planet1.

-- Matthias

Jens Axel Søgaard

unread,
Feb 19, 2013, 10:26:33 AM2/19/13
to Matthias Felleisen, us...@racket-lang.org, Daniel Prager
2013/2/19 Matthias Felleisen <matt...@ccs.neu.edu>:

> On Feb 19, 2013, at 6:00 AM, Daniel Prager wrote:
>
>> I've written an interactive turtle graphics package, complete with
>> animated turtle imagery, aimed at Dr Racket using parents with elementary-school aged kids.

I like the turtles!

> Thanks, that's great. In what way did you find the existing one lacking?

Just in case, here is the link to the documentation:
http://docs.racket-lang.org/turtles/index.html?q=turtle

--
Jens Axel Søgaard

Daniel Prager

unread,
Feb 22, 2013, 3:30:18 PM2/22/13
to us...@racket-lang.org
Thanks Sam and Matthias for the tips:  I've been able to clean up the directory structure and
add a (save-movie) command that writes out an animated gif.  

Matthias wrote:
> Thanks, that's great. In what way did you find the existing one lacking?

I did start with that existing package, but initially wanted to simplify the process of drawing pictures interactively, and boost the immediate appeal for my kids.  Specifically, I wanted:
* input and output directly in Dr Racket's REPL window, rather than an an "edit definitions-run-close graphics window" cycle.
* a realistic image of a turtle, rather than a triangle.

Based on observation of my kids I made improvements to enhance usability and appeal.  Main additions:
* (undo) and (redo) to improve interactivity
* facility to change the turtle's image into e.g. a pink girl
* replay all the turtle's steps as an animation: (movie) 
* (show-program)  to recap the interactive commands used so far for copying into the definitions window

Of these (movie) is definitely the "wow" feature.  

BTW: If someone would like to contribute, a bit-blt-based "color-in" operation, that would be great.

I should add that after taking Shriram's recent online PLAI course I restructured the whole thing around a sugared and desugared language.  This approach allowed me -- amongst other simplifications -- to cleanly separate out the chopping-out-into-frames needed for animation from the rest of the code.  Previously both modes of movement were smooshed together.

Dan

Matthias Felleisen

unread,
Feb 23, 2013, 1:19:05 PM2/23/13
to Daniel Prager, us...@racket-lang.org

Nice! Keep pushing this project -- Matthias



Reply all
Reply to author
Forward
0 new messages