Programming Animation Using Behavioral Programming

David Harel, Shani NitzanBM-FA (Revised Selected Papers) 2014

TL;DR

This paper introduces a novel approach to creating computer animations for hybrid systems by adapting "behavioral programming" (BP). It allows users to define both discrete and continuous behaviors for objects, which are then executed simultaneously to produce smooth, interactive animations, simplifying complex animation development.

What Problem Does This Paper Address?

Creating realistic and interactive animations, especially for systems with both continuous motion and discrete events (hybrid systems), is a complex task. Traditional animation methods can be cumbersome, and existing programming paradigms don't always naturally map to how humans describe system behavior. The authors aim to bridge this gap by leveraging Behavioral Programming (BP), a paradigm that focuses on defining system behavior through scenarios, to create a more intuitive and incremental way to program animations. This approach is particularly useful for scenarios where objects exhibit both smooth, continuous movement (like a bouncing ball) and sudden, discrete changes in behavior (like hitting a wall).

Methods

The core of the paper's contribution lies in adapting Behavioral Programming (BP) for animation. BP is a scenario-based programming paradigm where system behavior is defined by independent components called "b-threads." These b-threads synchronize using a publish-subscribe mechanism, atomically executing until a synchronization point where they specify "requested," "waited-for," and "blocked" events.

The authors' adaptation involves:

  • Motion B-Threads: These b-threads represent the continuous behavior of an object, such as its movement. They typically involve a loop that creates a "sleep" event for timing, waits for that event, requests a "takeStep" event, and then calculates the object's new position based on its velocity and elapsed time.
  • Control B-Threads: These b-threads manage discrete events and influence the motion b-threads. They can block or trigger events to alter an object's behavior, for example, by stopping motion when a collision is detected.
  • Hybrid System Integration: The approach naturally handles hybrid systems by allowing motion b-threads (continuous) and control b-threads (discrete) to interact through the BP synchronization mechanism. This allows for scenarios like a bouncing ball where the continuous motion is governed by gravity and velocity, while discrete events like hitting the ground trigger a change in direction.
  • Incremental Development: A key advantage highlighted is the ability to add new behaviors (b-threads) without altering existing ones, facilitating incremental development and verification of animation logic.

The paper specifically uses BPJ (Behavioral Programming in Java) as the implementation framework.

Datasets

Not discussed in the paper. The paper focuses on demonstrating the technique with custom-built examples like a bouncing ball, a water flow system, a billiard game, and flocking birds.

Key Insights and Ideas

  • BP as a Natural Fit for Animation: The scenario-based nature of BP aligns well with how animators and users often describe desired object behaviors and interactions, making it more intuitive than traditional imperative programming for animation.
  • Separation of Concerns: Motion b-threads handle continuous movement, while control b-threads manage discrete events and interactions. This separation simplifies the design and maintenance of complex animations.
  • Incremental Animation Construction: The ability to add new b-threads without modifying existing ones is crucial for building complex animations step-by-step and verifying each component's behavior.
  • Handling Hybrid Systems: The framework elegantly integrates continuous and discrete behaviors, which is fundamental for realistic simulations of physical systems.
  • Implicit Synchronization: The BP synchronization mechanism handles the coordination of multiple b-threads, abstracting away much of the complexity of managing concurrent behaviors.

Key Results

The paper demonstrates the effectiveness of its approach through several examples:

  • Bouncing Ball: Successfully models continuous motion under gravity and discrete changes in direction upon hitting the ground.
  • Water Flow: Creates lukewarm water by interleaving hot and cold water taps.
  • Billiard Game: Simulates the complex interactions of multiple balls, including collisions, border bounces, and balls falling into holes.
  • Flocking Birds: Implements the Boids algorithm, showcasing how individual behaviors and flocking rules can be managed with BP.

While quantitative results like performance metrics are not the primary focus, the qualitative results demonstrate the system's ability to produce smooth, interactive, and complex animations with a relatively straightforward programming model.

Limitations and Future Work

  • Optimization for Context Switching: The authors acknowledge that in complex scenarios with many objects and b-threads, the overhead of context switching between b-threads can become a bottleneck, especially with short clock ticks. They suggest optimizing the context switch mechanism.
  • Multiple Time Scales: While the current work allows for different clocks per object, further work is needed to make these behaviors truly independent while still synchronizing execution.
  • Formalizing Informal Descriptions: Research into how animations are described informally could lead to better formal programming language primitives for BP.
  • Direct Formula Integration: Incorporating the ability to directly use mathematical formulas for physical calculations within BP would be beneficial.
  • User-Friendliness for Non-Programmers: Enhancing BP to provide a better illusion of continuous motion and simplifying the system would make it more accessible to non-programmers.
  • Complex Animations: Future work could explore more complex animations involving compound objects, dynamic boundaries, and object merging/splitting.

Summary updated

BibTeX
@inproceedings{harel2014programming,
  author = {David Harel and Shani Nitzan},
  title = {{Programming Animation Using Behavioral Programming}},
  booktitle = {BM-FA (Revised Selected Papers)},
  year = {2014},
  doi = {10.1007/978-3-319-21912-7\_5},
}
Figure