| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,196
|
I've been tinkering with Robert Penner's easing equations and here's what I came up with so far...
This: PHP Code:
PHP Code:
Robert Penner's equations accept 4 arguments: t = time b = beginning value c = change in value d = duration Let's suppose we'd like to tween a clip across the stage. Our clip currently has an _x of 50 and we want it to move across the stage and stop at an _x of 500 within the time span of 10 seconds. From this scenario we can easily produce the following variables: startX = 50; endX = 500; duration = 10; To make R.Penner's equations work we need to supply our variables like so: t = ? b = 50; // startX; c = 450; // endX-startX; d = 10; // duration; As you can see "t" hasn't been determined yet. That's because "t" is dependant upon the amount of time to have passed since the tween was started. The "t" argument represents a number from 0 to "duration" (10) which will always be changing and essentially driving the clip across the stage to its goal position. Okay, so our clip is supposed to take 10 seconds to move across the stage, where will the clip be 3 seconds after we start a linear tween? The linear easing function looks like this: Math.linear = function(t, b, c, d){ return b+t/d*c; } The linear easing function is called like this: Clip._x = Math.linear(3, 50, 450, 10); Which would translate to: Clip._x = 50+3/10*450 Which would make Clip._x equal 185. Now that you (hopefully) have a grasp of how to use R.Penner's easing equations, let's compare using his to using mine. Comparing Easing Equations PHP Code:
When you're "EASING" (notice I didn't say tweening but said "EASING")... When you're easing between two values, you feed the easing equation a series of evenly spaced numbers and it returns a series of warped (unevenly spaced) numbers. Keeping your input values between 0 and 1 assures your output will always be a number between 0 and 1. This increases standardization and furthers abstraction since the function is less intimately entwined with its application (startX, endX, duration are no longer integral to the easing equation). Accepting and returning numbers within the same range has some other benefits which we'll discuss later. PHP Code:
Code:
E Q U I V A L E N C E
__Penner______ ______PiXELWiT__
Math.linearTween(3, 0, 1, 10) = Math.easeIn(.3, 1) >Linear = 1
Math.easeInQuad(3, 0, 1, 10) = Math.easeIn(.3, 2) \
Math.easeOutQuad(3, 0, 1, 10) = Math.easeOut(.3, 2) Quadratic = 2
Math.easeInOutQuad(3, 0, 1, 10) = Math.easeInOut(.3, 2) /
Math.easeInCubic(3, 0, 1, 10) = Math.easeIn(.3, 3) \
Math.easeOutCubic(3, 0, 1, 10) = Math.easeOut(.3, 3) Cubic = 3
Math.easeInOutCubic(3, 0, 1, 10) = Math.easeInOut(.3, 3) /
Math.easeInQuart(3, 0, 1, 10) = Math.easeIn(.3, 4) \
Math.easeOutQuart(3, 0, 1, 10) = Math.easeOut(.3, 4) Quartic = 4
Math.easeInOutQuart(3, 0, 1, 10) = Math.easeInOut(.3, 4) /
Math.easeInQuint(3, 0, 1, 10) = Math.easeIn(.3, 5) \
Math.easeOutQuint(3, 0, 1, 10) = Math.easeOut(.3, 5) Quintic = 5
Math.easeInOutQuint(3, 0, 1, 10) = Math.easeInOut(.3, 5) /
*function not yet written* = Math.easeIn(.3, 6) >Sentic? and beyond...
Earlier I mentioned that there are benefits to functions which accept and return numbers within the same range (i.e. a ratio from 0 to 1). If you look at the following code you'll notice I've modified one of my standard easing equation to use recursion as a way to "amplify" the easing results. PHP Code:
If you're on your toes you might notice that the "easeOutSin" function's arguments are similar to the previously discussed (easeIn, easeOut, easeInOut) function's arguments in that they all accept a ratio followed by a whole number and increasing that whole number significantly increases the easing effect. Pretty handy huh? Yay for standards. While this doesn't cover every one of Robert Penner's easing equations it does cover some of the most popular ones. If you have any further comments please feel free to add them. -PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. Last edited by pixelwit; 03-07-2004 at 09:43 PM.. |
|
|
|
|
|
#2 |
|
Canadian Flasher
Join Date: May 2002
Location: T dot O dot
Posts: 1,651
|
|
|
|
|
|
|
|
|
|
#3 |
|
Macromedia Mercenary
|
Color me impressed. Good stuff, PiXeLWiT. |
|
|
|
|
|
#4 |
|
Banned by AS.org Staff
Join Date: Mar 2002
Posts: 10,534
|
Like he said!
Couldn't resist! Now if Pixelwit could only address all the latest threads on his plageFlip bit, guess everybody would have a happy weekend! ![]() |
|
|
|
|
|
#5 | |
|
Macromedia Mercenary
|
Quote:
|
|
|
|
|
|
|
#6 |
|
done
Join Date: Jun 2001
Location: portland, or
Posts: 8,048
|
*picks up blo-horn*
STEP AWAY FROM THE KEYBOARD AND COME OUTSIDE WITH YOUR HANDS ABOVE YOUR HEAD. pixelwit, obviously you've been staring into your monitor for way to long... get out and get some fresh air. btw. nice.
__________________
tg --- what the hell was i thinking? |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Aug 2002
Location: Philly
Posts: 2,580
|
wow. How long did it take you to figure that out?
very impressive.
__________________
I need a new signature! |
|
|
|
|
|
#8 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,196
|
I've updated the code a little bit to facilitate the addition of a wider variety of easing equations. Exponential, sinusoidal and circular are included as examples.
PHP Code:
The second argument "p" should be a whole number greater than 0. Numbers greater than 1 increase the easing effect. The third argument "f" should be a reference to an easing Function. -PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. |
|
|
|
|
|
#9 |
|
Macromedia Mercenary
|
Dope.
|
|
|
|
|
|
#10 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,196
|
I discovered you can ease in and out using 2 different types of easing techniques at the same time. Typical easing in and out produces a "symmetrical" pattern, equally slow toward the ends and equally fast toward the middle. However this new approach lets you do a slow ease-in with a fast ease-out and the other way around. That might not be real easy to visualize so I provided some code for clarification. Just copy and paste it into a new file and run it to see what's going on.
PHP Code:
http://www.pixelwit.com
__________________
There are no answers, only choices. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|