Basic Animation Tutorial

= Overview =

Animation in multimedia relies on a perception phenomenon referred to as “persistence of vision.” Human vision, compared with animal predators, is relatively poor, both in terms of resolution and response time. Some hawks, for example, can spot a mouse moving in a field almost a thousand meters away, while in flight.

Animation on a computer consists basically of quickly erasing and re-creating the same or a slightly altered image a short distance from the original image location. If done quickly enough, the viewer will perceive motion. Animation software provides tools to facilitate animation. In AgentSheets, the user has the opportunity to experience to process first hand!

= Tutorial Example =

In the animation demo] example, a jumping frog is used to demonstrate two techniques to create the effect of animation. The simplest approach, and one often used by beginning students, is to use a sequence of “move” and “wait” actions. However, a better approach, and one which is necessary when there are multiple animated agents, is to use a conditionally timed technique via the “once every” condition and repetitive calls to a separate method. In the example described below, an agent called “jumper” is animated, and the choice of animation technique is controlled via keyboard input. In an actual implementation, of course, one would choose a single method, thus eliminating some of the rules from the tutorial.

= Single Agent vs. Multiple Agent Animation = The animation demo contains two worksheets to demonstrate animation:



All of the jumping frog agents are identical, so one would expect them to behave identically and essentially simultaneously.

Below is the “While Running” behavior of the “jumper” agent:



As can be seen, the “space” key invokes the “usewait” method; the “J” key invokes the “useloop” method by virtue of setting an agent attribute, “timestart” to “1”.

Single Agent Animation: Move and Wait
When the “space” key is pressed, the “usewait” method is invoked (see below). This method executes a sequence of “move up” and “move down” actions, each separated by a “wait” action. The amount of time to wait is controlled by the “delay” simulation property:



With only one agent, the move/wait sequence works. The frog appears to jump up and fall back. Changing the value of “delay” controls the rate of ascent/descent. However, running the simulation on the worksheet with multiple frogs is much different. Depending on the delay value, only a few of the frogs jump; the shorter the delay, the more frogs jump, but not all frogs, nor do they jump together. The reason is that the “wait” action suspends simulation, which means that things get processed sequentially. Thus, one frog’s actions are processed, followed by the next, etc. In addition, key stroke inputs are retained in a queue for only a finite time – about one second – which means that if there has been sufficient delay for the time to expire, an agent will not “see” the inputs. In the example with “delay” set to 0.1 second, and with 5 delays in the rule, only two frogs will “see” the key input (5 x 0.1 second x 2 = 1 second). The move/wait repetition is not a satisfactory technique for multiple agents. In addition, the two frogs who do receive the input do not move together, but, rather, sequentially. Clearly, another technique is needed. Fortunately, there is one.



Multi-agent animation: the “Once Every” Condition As a Timer
Examine, again, the rules in the “While Running” method shown earlier. Note that pressing the “J” key does not actually invoke a method to cause movement. Rather, it simply sets an agent attribute, “timestart” to the value “1”. This attribute is what controls whether movement occurs under the control of the “useloop” method, shown below. Note that the third rule in “While Running” executes only if “timestart” is set to “1”, and also, it executes every “delay” seconds until/unless the value of “timestart” changes. Now, look at the “useloop” method behavior (below). There are actually two methods involved. The “useloop” method controls the execution and the “animate” method performs the actual movement of the “jumper” agent.

As with the “usewait” method, animation is a series of step-wise movements with delays in between. In this technique, however, simulation is not suspended via the “wait” action. Instead, the “once every” condition in the “While Running” method controls the timing. This permits AgentSheets to continue running the simulation; whereas, the “wait” action suspends simulation. This means that ALL agents can continue to be polled in order to check and satisfy conditions in their “While Running” behavior. And this means that all agents that respond to the key input can be serviced at the same time, rather than sequentially, as with the move/wait approach.

Examining the behavior in the “useloop” method below, we see that the first rule continues to invoke the “animate” method, which performs the actual movement of the “jumper” agent, as long as the “animation” count does not exceed 5. Keep in mind that agent attribute values are initialized to zero, so that reaching “5” means the sixth iteration. Once this limit is exceeded, the second rule resets both the “animation” and “timestart” attributes to zero, thus terminating the movement by disabling the third rule in the “While Running” method. Finally, the “animate” method simply divides the count (6 increments) into halves: the first half moving up and the second half moving down.