Project 4 - Animation Logic

Project 4 - Animation

Animation Based on Finite State Machine Logic

The example programs below give simplified examples of animation that is controlled using an animation state variable and an animation position variable to control the animation.

Simple Rotate Animation

In the example project below, a rotate animation is controlled by a State Variable: rotateState which can be in one of 3 possible states: "UP", "DOWN", or "STOP".

This rotateState variable provides logic to control the animation using a finite state machine structure.

Example Khan Academy Programs:

Rotate Animation: https://www.khanacademy.org/computer-programming/simpleanimation/6670336845873152

Animation state variable: rotateState: can be in one of 3 possible animation states: "UP", "DOWN", or "STOP"

Animations position variable: angle.

  • When in "UP" state, angle is incremented: angle++

  • When in "DOWN" state, angle is decremented: angle--

  • angle is restricted to range of values between minAngle and maxAngle.

Animation events:

  • When the angle >= maxAngle, then the animation state: rotateState is set to: "DOWN"

  • When angle <= minAngle, then animation state: rotateState is set to: "UP"

  • When the count variable equals maxCount, rotateState is set to: "STOP" to stop the animation.

Animation of line and offset rectangle

Additional Simplified Animation Examples

https://www.khanacademy.org/computer-programming/animation-demo-simple/5581835098324992

https://www.khanacademy.org/computer-programming/simple-rotateanimation/6227637252587520

Last updated

Was this helpful?