A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: smoothness

Hybrid View

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    Slovenia
    Posts
    193
    Well, when I want to create an easing function, I just use what we have learnt during the math classes.

    Since speed is the first derivative of the distance traveled against time, you may "invent" speed functions by looking at the integral of a random function you like most. A quadratic equation is quite good for that, a sine function can also be used (you can use whatever you want). Just integrate, select the interval you like most (the interval is time), and induce a parameter that generates an area (under the speed curve) that suits your distance.

    An example of derivation of a quadratic function:
    Code:
    Lets say we want the movie to move in a time interval of 40 frames (i.e. timeinterval=40):
    speed = a(- t^2 + (timeinterval/2)^2)
    Integrate the speed function against t (lower bound is -(timeinterval/2) and the upper is timeinterval/2):
    distance = a(-((timeinterval/2)^3)/3+(timeinterval/2)^2×timeinterval/2)-
    a(-((-timeinterval/2)^3)/3+(timeinterval/2)^2×-timeinterval/2)
    If you simplify this, you get:
    distance = (a×timeinterval^3)/6
    But you know the distance - say distance is 500 (pixels), and can now calculate the value of parameter a:
    a = distance×6/timeinterval^3
    Now we have a function of speed:
    speed = distance × 6 / timeinterval^3(-t^2 + (timeinterval/2)^2)
    That's the derivation of an example function. If you don't see the power of this method... well here we go:
    1. you may create functions that dont ease only in a linear direction, but may change the direction of movement according to any function (say speed becomes negative, or jups up a luttle and then back down...)
    2. you may produce virtually any easing function
    3. you may practice your math and discover not to create speed functions but displacement functions - which are faster and more accurate - they do not involve intergration (rather trivial actually)
    The disadvantages of the method:
    1. inaccurate

    Here's an example of the derived function...
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center