{ (define LIBNAME "Animated Images, Simulating Worlds") (include "head.tinc") }

The teachpack provides two kinds of functions. The first five allow students to simulate a small world of animated drawings and games:

  • {(idx run-simulation)} : Nat Nat Number [Nat -> Scene] -> true
    (run-simulation width height r create-image) creates and shows a width x height canvas, starts a clock, ticking every r (usually fractional) seconds, and, every time the clock ticks, it applies create-image to the number of ticks passed since this function call.

    In addition, the function pops up a frame and displays the pictures that create-image generates. The result is a simple animation.

    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)
    
    

    The teachpack assumes two basic kinds of data:

  • {(idx big-bang)} : Nat Nat Number World -> true
    (big-bang width height n w) creates and shows a width x height canvas, starts the clock, makes it tick every n seconds, and makes w the first world
  • {(idx big-bang)} : Nat Nat Number World Boolean -> true
    big-bang takes an optional fifth argument. If it is true, the world allows the generation of images from the animation, including an animated GIF image
  • {(idx on-tick-event)} : (World -> World) -> true
    (on-tick-event tock) means that DrScheme must call tock on the current world every time the clock ticks; it uses the result as the next world
  • {(idx on-key-event)} : (World KeyEvent -> World) -> true
    (on-key-event change) means that DrScheme must call change on the current world and a (representation of the) keyevent for every keystroke the programmer (user of the computer) makes; it uses the result as the next world
    
       ;; A KeyEvent is one of: 
       ;; -- Char (char?)
       ;; -- Symbol (symbol?)
    
       When the Keyevent is a char, the programmer (user of the computer) has hit an
       alphanumeric key. Symbols such as 'left, 'right,
       'up, 'down, 'release denote arrow keys
       or the events of releasing a key on the keypad. 
    
  • {(idx on-mouse-event)} : (World Nat Nat MouseEvent -> World) -> true
    (on-mouse-event clack) means that DrScheme must call clack on the current world, the current x and y coordinates of the mouse, and and a (representation of the) mouse event for every action of the mouse the programmer (user of the computer) makes; it uses the result as the next world
    
      ;; A MouseEvent is one of:
      ;; - 'button-down
      ;; - 'button-up
      ;; - 'drag
      ;; - 'move
      ;; - 'enter
      ;; - 'leave
    
       The symbols denote the appropriate action with the mouse and (any of)
       its button(s).
    
  • {(idx on-redraw)} : (World -> Scene) -> true
    (on-redraw world->scene) means that DrScheme calls world->image whenever the canvas must be redrawn (usually after a tick event/a keyboard event/a mouse event has occurred); the function consumes the current world and produces a scene, which is then displayed in the teachpack's canvas
  • {(idx end-of-time)} : String u Symbol -> World
    When DrScheme evaluates (end-of-time), it stops the clock and displays the given string or symbol; no further tick events, key events, or redraw events take place until the world is created again.
  • The rest are functions for creating scenes:

  • {(idx nw:rectangle)} : Nat Nat Mode Color -> Image
    (nw:rectangle width height mode color) creates a width x height rectangle, solid or outlined, with its anchor in the NW corner
  • {(idx empty-scene)} : Nat Nat -> Scene
    (empty-scene width height) creates a width x height "scene" (frame with origin in NW)
  • {(idx place-image)} : Image Number Number Scene -> Scene
    (place-image image x y scene) places image at (x,y) into scene; (x,y) are comp. graph. coordinates
  • {(idx add-line)} : Scene Number Number Number Number Color -> Scene
    (add-line scene x0 y0 x1 y1 c) places a line of color c from (x0,y0) to (x1,y1) into scene; (x,y) are comp. graph. coordinates; in contrast to the {(idx image.ss)} add-line function, this one cuts off those portions of the line that go beyond the boundaries of the given Scene.
  • {(idx run-movie)} : (Listof Image) -> true
    (run-movie loi) shows the list of images in loi, time-delayed

  • Image Manipulation

    Finally, the teachpack provides all the functions that image.ss provides except add-line, which has a slightly different functionality. For completeness, the documentation of this teackpack is included here: {(include "image-content.tinc")}

    {(include "foot.tinc")}