[racket-dev] Caching rendered icons

From: Neil Toronto (neil.toronto at gmail.com)
Date: Thu Jan 12 18:33:39 EST 2012


BTW, having been inspired by Jay's latest elegant macro, I've shrunk the 
implementation to 21 lines of code. (That's good for a tutorial.) It 
works a little differently now, too. I think it's better.

Here's an example that bakes a list of stickman animation frames into a 
compiled module:

   (require images/icons/stickman)
   (define stickman-height 18)
   (define num-running-frames 12))

(define running-frames
    (for/list ([t  (in-range 0 1 (/ 1 num-running-frames))])
      (running-stickman-icon t run-icon-color "white" run-icon-color

The expression within `compiled-bitmap-list' is evaluated at compile 
time. It and `compiled-bitmap' make any bitmap or list of bitmaps 
generated at compile time into runtime values. The above expands to

     (list (make-object bitmap% (open-input-bytes #"...") 'png)

There are very few restrictions on the arguments now. They just have to 
be valid in the transformer phase.

Neil T

On 01/12/2012 03:54 PM, Robby Findler wrote:
> I think this is a great example to base a tutorial example on. Neil:
> I'd be happy to help with the writeup, if you'd be willing to make a
> first attempt.
> Robby

Posted on the dev mailing list.