[plt-scheme] pause or wait?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Jun 7 14:41:23 EDT 2006

> When running recursive procedures that have an effect on the screen 
> (such as an animation) it sometimes nice to have them pause between each 
> call. I looked for such a PAUSE or WAIT primitive but couldn't find one. 
> Any pointers?

Hi Knubee,

If we're using the draw.ss teachpack from How to Design Programs,


then we should be able to use the function sleep-for-a-while mentioned in 
exercise 6.6.6.

If we're using the module language, you can still access teachpacks by 
requiring the appropriate one from the 'htdp' collection.  For example:

(module test-drawing mzscheme
   (require (lib "posn.ss" "lang")
            (lib "draw.ss" "htdp")
            (lib "etc.ss"))

   ;; draw-shrinking-circle: posn number number
   ;; draws a circle that shrinks.
   (define (draw-shrinking-circle center-posn current-radius min-radius)
       [(> current-radius min-radius)
         (draw-circle center-posn current-radius 'black)
         (sleep-for-a-while .05)
         (draw-circle center-posn current-radius 'white)
         (draw-shrinking-circle center-posn
                                (sub1 current-radius)
       [else true]))

   (start 300 300)
   (draw-shrinking-circle (make-posn 150 150) 100 50))

Best of wishes!

Posted on the users mailing list.