Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 13: A Module of Simple Animations

Chapter 13: A Module of Simple Animations

pp. 163-186

Authors

, Yale University, Connecticut
  • Add bookmark
  • Cite
  • Share

Summary

In previous chapters you learned how to draw simple geometric shapes in a graphics window. Although you also learned how to manipulate these pictures somewhat using the mouse, they were otherwise static. In this chapter I will explain how to make these pictures dynamic; that is, how to program animations. In doing so you will learn several new ideas, such as how to use timers and how to use polymorphism and type classes in unique ways.

module Animation where

import Shape

import Draw

import Picture

import SOEGraphics hiding (Region)

import qualified SOEGraphics as G (Region)

import Win32Misc (timeGetTime)

import Word (word32ToInt)

What is an Animation?

An animation is a continuous, time-varying image. However, the animations that you see in the movies, on TV, or on your computer screen only seem to be moving continuously. In reality they are created by a sequence of static images - called frames that are displayed in such rapid succession that they appear to be continuous to the human eye. The rate at which this phenomenon occurs is somewhere between 20 and 30 times per second, depending on lighting conditions and other factors. I will use the rate of 30 times per second, or 30 Hertz, abbreviated 30 Hz. Televisions, computers, and motion pictures all use this fundamental physiological phenomenon to give the illusion of continuous movement.

So the question is, how do we program an animation? The only graphics 10 operation that we have discussed so far is drawInWindow, but note that drawing things using this operation is accumulative. That is, we never erase anything, nor even do so much as clear the screen. Even the user interaction given in Chapter 10 does not clear the screen; each successive rendition of the stack of regions is drawn right over the previous rendition. This works because each new picture completely hides the old one.

This will not work, however, if we are drawing a person walking across the screen, or a ball bouncing in a box.

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$79.00
Hardback
US$182.00
Paperback
US$79.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers