On this page:
run-simulation
Version: 4.1.2.4

2 Simple Simulations

(run-simulation w h r create-image [gifs?])  true
  w : natural-number/c
  h : natural-number/c
  r : number?
  create-image : (-> natural-number/c scene)
  gifs? : boolean? = #f

creates and shows a canvas of width w and height h , starts a clock, making it tick every r (usually fractional) seconds. Every time the clock ticks, drscheme applies create-image to the number of ticks passed since this function call. The results of these applications are displayed in the canvas.

The fifth (and last) argument is optional. Providing true as the fifth argument causes drscheme to collect the scenes that the animation generates and to create an animated GIF from the results. Both the intermediate images as well as the final animated GIF are saved in a user-specified directory. This is useful for writing documentation and for describing students work.

Example:

  (define (create-UFO-scene height)
    (place-image UFO 50 height (empty-scene 100 100)))
  
  (define UFO
    (overlay (circle 10 'solid 'green)
             (rectangle 40 4 'solid 'green)))
  
  (run-simulation 100 100 (/ 1 28) create-UFO-scene)