Reproducing A Clever Animation Product, Part 21

The last subject I wanted to explore was animation effects, which is to say defining tweens that proceed from beginning to end in a fashion that is other than linear, which is the default I’ve been using to this point. The tweens are defined using the addTransformToList function, as shown in multiple instances below.

If, instead of defining a linear tween, we wanted to define one that behaved differently, we’d have to provide an alternate string or object literal. The information would have to include as many parameters as required to govern the desired effect. Here’s one I did for an animation on one of my intro pages; it simply specifies a string and the details are hard-coded in the tween function (in this case a bcDefineLeftTween function).

The idea is that the element would start in a given spot, get kicked to the right by some specified amplitude, vibrate back to the original position in a sine wave pattern, with a vibration having a specified period, and with a specified decay (during which the vibration gets smaller and smaller). I used parameters to govern the amplitude (the 100.0, in pixels), period (the 0.3, modifying the cumulative angle), and decay (the (omega-i) / (omega-alpha) term) so I might define an object literal of the form:

If I wanted the vibrate starting to the left I would just change the sign of the last term in the first line of the relevant block like this:

This would make the tween start in the original location but as the quantity i – alpha began to increase the cosine value would first go negative instead of positive.

The tween definitions here aren’t bad but we’d certainly want to implement something more modular. We wouldn’t want to have to embed all that specialized code in each function that defines a tween, we’d probably want to use a functional parameter that gets its parameters set in one place, then is called in the tween function using a standard-looking interface that takes only the alpha, omega, and i values as inputs. Any other method would involve too much duplication of code.

If you are wondering, this is implemented in the Greensock product in a very powerful way. They’ve created a page which lets you see how it all works in detail, here. As I’ve stated before, the folks who’ve created this product have done such a nice job with it, and their licensing terms are so easy, that it would be crazy to try to reverse-engineer or duplicate the whole thing.

One type of effect I do want to create involves simulating gravity, so that when you give an element an initial velocity moving upward, a downward velocity increment is added during every animation step. Combined with a modest leftward or rightward movement, an object can be made to “fly” in a natural-looking arc. A bunch of objects animated together in this way could be made to look like a fountain of sorts. See here (the effect starts about halfway through the title animation) for the inspiration for this exercise, which will begin next week.

This entry was posted in Tools and methods and tagged , , . Bookmark the permalink.

Leave a Reply