On this page:
7.1 Animation player

7 2/20: Playing Animations

Due: 2/20.

7.1 Animation player

Language: class/2.

In this assignment, we’ll build a video player for animations. The player will support play, pause, fast-forward, and rewind. A player will interact with an Animation solely through the following interface:

;; An Animation implements:

;; next : -> Animation

;; prev : -> Animation

;; render : -> Scene

The next and prev methods work on all Animations. In particular, the prev method on the first frame of an animation should stay at the first frame, and next of the last frame should stay on the last frame.

Here is an example implementation of an Animation that displays a sequence of numbers:

#lang class/0
(define WIDTH 200) ; Animation dimension in PX.
(define-class count-animation%
 (fields n)
 (define (next)
   (new count-animation% (add1 (send this n))))
 (define (prev)
   (new count-animation% (max 0 (sub1 (send this n)))))
 (define (render)
   (overlay (text (number->string (send this n)) (quotient WIDTH 4) "black")
            (empty-scene 200 200))))
  1. The Player user interface

    The user can interact with a player through the keyboard: "p" plays, "f" fast-forwards, "r" rewinds, and "s" stops playing.

    The fast-forward mode should skip every other frame of the animation. The rewind should go back through the animation.

  2. Animations

    An animation is anything that implements the above interface. You need to implement several ways to construct animations.

    • First, animations that are constructed from lists of Scenes.

    • Second, animations that consists of a function from a number to a frame. For example, when given the following function, your animation creator should produce the animation as the example above:
      (lambda (i) (overlay (text (number->string i) 50 "black")
                           (empty-scene 200 200)))

    • Third, you should create an implementation of Animation that wraps an object with on-tick and to-draw methods. That is, the constructor should take an object that supports the following World interface:
      ;; A World implements
      ;;  to-draw : -> Scene
      ;;  on-tick : -> World
      and it should render the Scenes that the World produces.

    Finally, you should use the third implementation to play an animation of a playing animation. You should demonstrate this in your solution with one of your other animations.