Glimmr Canvas Animation

version 1/111030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Adding custom easing equations

    Adding new easing equations is both easy and difficult. It is easy in that there's not much to the mechanics of the process. We simply define a "to decide" phrase using a certain rigid form for the preamble. Here is the preamble for one of the phrases included with GCA. We would copy this preamble exactly, replacing the capitalized phrase with the name of our equation:

        To decide what number is QUADRATIC EASING IN for time (t - a number) duration (d - a number) beginning (b - a number) change (c - a number ) (this is the QUADRATIC EASING IN rule):

    Now on to what's hard about writing new equations. First, coming up with them in the first place. GCA borrows equations from various places around the web (see the resources listed above and in the comments to the extension's source code). There are certainly other equations out there, and the easiest thing will be to borrow those.

    The next difficult thing is dealing with Inform's limited math capabilities. Inform does not follow the standard rules for precedence in mathematical operations, so we need to be very liberal in using parentheses to spell out for Inform which operations should be grouped together. Inform also does not allow fractions, so if our equation depends on fractional multipliers or divisors, we will need to use the functionality provided by Michael Callaghan's Fixed Point Maths (FPM) extension. GCA provides some short cuts for making FPM code a bit more readable: we can double the main mathematical operators to replace the "real number" operations provided by FPM. For example,

        (120 ** 2) ++ 17 would be equivalent to

        (120 real times 2) real plus 17 in FPM's notation

    Here's an example of a relatively simple equation from those included with GCA:

        To decide what number is QUADRATIC EASING IN for time (t - a number) duration (d - a number) beginning (b - a number) change (c - a number ) (this is the QUADRATIC EASING IN rule):
            let t1 be (t as a fixed point number) // d;
            decide on (c ** t1 ** t1) ++ b as an integer.

    Once we've completed our equation, we can refer to it just as if it were one of the built-in equations; no additional steps are needed:

        My anim-track is an animation track. The easing is the polysyllabic easing out rule.