/** * VERSION: 12.0.5 * DATE: 2013-03-27 * AS3 * UPDATES AND DOCS AT: http://www.greensock.com/roughease/ **/ package com.greensock.easing { import com.greensock.easing.core.EasePoint; /** * Most easing equations give a smooth, gradual transition between the start and end values, but RoughEase provides * an easy way to get a rough, jagged effect instead, or you can also get an evenly-spaced back-and-forth movement * if you prefer. Configure the RoughEase by passing an object to the constructor or config() method with any * of the following properties (all are optional): * *
Linear.easeNone
)1
)20
)clamp
to true
will prevent points from
* exceeding the end value or dropping below the starting value. For example, if you're tweening the x
* property from 0 to 100, the RoughEase would force all random points to stay between 0 and 100 if
* clamp
is true
, but if it is false
, x could potentially jump
* above 100 or below 0 at some point during the tween (it would always end at 100 though in this example)
* (Default: false
)."in" | "out" | "both" | "none"
) - to make the strength of the
* roughness taper towards the end or beginning or both, use "out"
, "in"
,
* or "both"
respectively. (Default: "none"
)randomize
to false
to make the points zig-zag evenly across the ease.
* Using this in conjunction with a taper
value can create a nice effect. (Default: true
)For a visual example and more details, check out http://www.greensock.com/roughease/.
* *Example code
*Copyright 2010-2014, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for Club GreenSock members, the software agreement that was issued with the membership.
* * @author Jack Doyle, jack@greensock.com */ public class RoughEase extends Ease { /** The default ease instance which can be reused many times in various tweens in order to conserve memory and improve performance slightly compared to creating a new instance each time. **/ public static var ease:RoughEase = new RoughEase(); /** @private **/ private static var _lookup:Object = {}; //keeps track of all named instances so we can find them in byName(). /** @private **/ private static var _count:int = 0; /** @private **/ private var _name:String; /** @private **/ private var _first:EasePoint; /** @private **/ private var _prev:EasePoint; /** * Constructor * * @param vars a generic object with any of the following properties (all are completely optional): *Linear.easeNone
)1
)20
)clamp
to true
will prevent points from
* exceeding the end value or dropping below the starting value. For example, if you're tweening the x
* property from 0 to 100, the RoughEase would force all random points to stay between 0 and 100 if
* clamp
is true
, but if it is false
, x could potentially jump
* above 100 or below 0 at some point during the tween (it would always end at 100 though in this example)
* (Default: false
)."in" | "out" | "both" | "none"
) - to make the strength of the
* roughness taper towards the end or beginning or both, use "out"
, "in"
,
* or "both"
respectively. (Default: "none"
)randomize
to false
to make the points zig-zag evenly across the ease.
* Using this in conjunction with a taper
value can create a nice effect. (Default: true
)
*
* TweenLite.from(mc, 2, {alpha:0, ease:RoughEase.create(1.5, 15)});
*
*
* @param strength amount of variance from the templateEase (Linear.easeNone by default) that each random point can be placed. A low number like 0.1 will hug very closely to the templateEase whereas a larger number like 2 will allow the values to wander further away from the templateEase.
* @param points quantity of random points to plot in the ease. A larger number will cause more (and quicker) flickering.
* @param clamp If true, the ease will prevent random points from exceeding the end value or dropping below the starting value. For example, if you're tweening the x property from 0 to 100, the RoughEase would force all random points to stay between 0 and 100 if restrictMaxAndMin is true, but if it is false, a x could potentially jump above 100 or below 0 at some point during the tween (it would always end at 100 though).
* @param templateEase an easing equation that should be used as a template or guide. Then random points are plotted at a certain distance away from the templateEase (based on the strength parameter). The default is Linear.easeNone.
* @param taper to make the strength of the roughness taper towards the end or beginning or both, use "out", "in", or "both" respectively here (default is "none").
* @param randomize to randomize the placement of the points, set randomize to true (otherwise the points will zig-zag evenly across the ease)
* @param name a name to associate with the ease so that you can use RoughEase.byName() to look it up later. Of course you should always make sure you use a unique name for each ease (if you leave it blank, a name will automatically be generated).
* @return easing function
*/
public static function create(strength:Number=1, points:uint=20, clamp:Boolean=false, templateEase:Ease=null, taper:String="none", randomize:Boolean=true, name:String=""):Ease {
return new RoughEase(strength, points, clamp, templateEase, taper, randomize, name);
}
/**
* @private
* DEPRECATED
* Provides a quick way to look up a RoughEase by its name.
*
* @param name the name of the RoughEase
* @return the RoughEase associated with the name
*/
public static function byName(name:String):Ease {
return _lookup[name];
}
/**
* Translates the tween's progress ratio into the corresponding ease ratio. This is the heart of the Ease, where it does all its work.
*
* @param p progress ratio (a value between 0 and 1 indicating the progress of the tween/ease)
* @return translated number
*/
override public function getRatio(p:Number):Number {
var pnt:EasePoint = _prev;
if (p > _prev.time) {
while (pnt.next && p >= pnt.time) {
pnt = pnt.next;
}
pnt = pnt.prev;
} else {
while (pnt.prev && p <= pnt.time) {
pnt = pnt.prev;
}
}
_prev = pnt;
return (pnt.value + ((p - pnt.time) / pnt.gap) * pnt.change);
}
/** @private [DEPRECATED] Disposes the RoughEase so that it is no longer stored for easy lookups by name with byName()
, releasing it for garbage collection. **/
public function dispose():void {
delete _lookup[_name];
}
/** @private [DEPRECATED] name of the RoughEase instance **/
public function get name():String {
return _name;
}
/** @private [DEPRECATED] name of the RoughEase instance **/
public function set name(value:String):void {
delete _lookup[_name];
_name = value;
_lookup[_name] = this;
}
/**
* Permits customization of the ease with various parameters.
*
* @param vars a generic object with any of the following properties (all are completely optional):
* Linear.easeNone
)1
)20
)clamp
to true
will prevent points from
* exceeding the end value or dropping below the starting value. For example, if you're tweening the x
* property from 0 to 100, the RoughEase would force all random points to stay between 0 and 100 if
* clamp
is true
, but if it is false
, x could potentially jump
* above 100 or below 0 at some point during the tween (it would always end at 100 though in this example)
* (Default: false
)."in" | "out" | "both" | "none"
) - to make the strength of the
* roughness taper towards the end or beginning or both, use "out"
, "in"
,
* or "both"
respectively. (Default: "none"
)randomize
to false
to make the points zig-zag evenly across the ease.
* Using this in conjunction with a taper
value can create a nice effect. (Default: true
)