Teachpacks for How to Design Programs

# Animated Images

### world.ss

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

- `big-bang : Number Number 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
- `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
- `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.

- `on-redraw : (World -> Image) -> true`
  `(on-tick-event world->image)` means that DrScheme calls `world->image` whenever the canvas must be redrawn; the result is displayed in the teachpack's canvas
- `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:

- `nw:rectangle : Number Number 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
- `empty-scene : Number Number -> Scene`
  `(empty-scene width height)` creates a width x height "scene" (frame with origin in NW)
- `place-image : Image Number Number Scence -> Scene`
  `(place-image image x y scene)` places image at (x,y) into scene; (x,y) are comp. graph. coordinates
- `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
- `run-movie : (Listof Image) -> true`
  `(run-movie loi)` shows the list of images in loi, time-delayed

  Finally, the teachpack provides all the functions that image.ss provides.