PencilCoder

Modeling Motion!

Goals:

  • Develop algorithms to simulate realistic motion

Coding Snippets:

  • coding snippets
  • An effective technique for modeling motion involves focusing on a sprite's coordinates.
  • The key is to track not only the coordinates (x and y), but also the rate of change of those coordinates (dx and dy).
  • Computing x and y and dx and dy separately simplifies the conditional logic needed when a sprite reaches a boundary (such as the edge of the screen).
  • Different formulas for computing dx and dy result in different types of movements.

Math and Computer Concepts:

  • There are many ways to model motion, each with its own advantages and disadvantages. This lesson focuses on an approach that models motion based on position and change in position.
  • dx and dy illustrationThe variable names dx and dy used in the coding snippet come from math. These names stand for "delta x" and "delta y", math-speak for "change in x" and "change in y".

Activities:

Save each of the following in a folder called Motion.