[plt-scheme] I miss end-of-time...

From: engineer at alum.mit.edu (engineer at alum.mit.edu)
Date: Fri Mar 12 11:34:24 EST 2010

I just came across stop-with.  That looks like a more direct replacement for
end-of-time.  (stop-with -1) does cause an error, because one last call to
render is made, but no negatives, or even booleans, are needed now.  Just
plan for one more render after you've pressed a key.  By the way, the doc
for stop-with does not mention that one last call to render.

Here's a 5x version:

;; ISL+
(require 2htdp/universe)
(require 2htdp/image)

(define (render n)
  (place-image (circle n 'solid 'red)
               50 50
               (rectangle 100 100 'solid 'white)))

(big-bang 1
          (on-tick add1 1/5)
          (on-draw render)
          (on-key  (lambda (n key)
                     (stop-with n))))


Going with a shrinking example, like Matthias's, allows for a simpler render
function.

-----Original Message-----
From: plt-scheme-bounces at list.cs.brown.edu
[mailto:plt-scheme-bounces at list.cs.brown.edu] On Behalf Of Matthias
Felleisen
Sent: Thursday, March 11, 2010 4:12 PM
To: Stephen Bloch
Cc: PLT-Scheme Mailing List
Subject: Re: [plt-scheme] I miss end-of-time...


On Mar 11, 2010, at 2:34 PM, Stephen Bloch wrote:

> Try this: write an animation of a disk whose radius starts at 0 and  
> grows by 1 pixel per second.  The animation stops when the user  
> presses any key on the keyboard.

Here it is:

;; ISL+
(require 2htdp/universe)
(require 2htdp/image)

(big-bang 100
           (on-tick sub1)
           (on-draw (lambda (n) (circle (+ n 1) 'solid 'red)))
           (stop-when negative? (lambda (n) (text "stopped" 11 'red)))
           (on-key  (lambda (n key)
                      (if (key=? key "k") -1 n))))

  
                         
_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.