You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/05/04 18:14:32 UTC
[46/50] [abbrv] git commit: [flex-asjs] [refs/heads/spark] - Added
easing functions to CreateJS framework. Adding easing functions to example.
Added easing functions to CreateJS framework. Adding easing functions to example.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/1d424cbf
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/1d424cbf
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/1d424cbf
Branch: refs/heads/spark
Commit: 1d424cbf3cebfe520fe0947aef2c4bcd313f3b67
Parents: fe3adff
Author: Peter Ent <pe...@apache.org>
Authored: Mon May 2 12:26:26 2016 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Mon May 2 12:26:26 2016 -0400
----------------------------------------------------------------------
.../CreateJSExample/src/CreateJSExample.mxml | 5 +
.../CreateJS/src/main/flex/CreateJSClasses.as | 1 +
.../flex/org/apache/flex/createjs/tween/Ease.as | 672 +++++++++++++++++++
.../org/apache/flex/createjs/tween/Effect.as | 10 +
.../org/apache/flex/createjs/tween/Sequence.as | 6 +-
5 files changed, 693 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1d424cbf/examples/flexjs/CreateJSExample/src/CreateJSExample.mxml
----------------------------------------------------------------------
diff --git a/examples/flexjs/CreateJSExample/src/CreateJSExample.mxml b/examples/flexjs/CreateJSExample/src/CreateJSExample.mxml
index bce0e15..2b127f7 100644
--- a/examples/flexjs/CreateJSExample/src/CreateJSExample.mxml
+++ b/examples/flexjs/CreateJSExample/src/CreateJSExample.mxml
@@ -30,6 +30,7 @@ limitations under the License.
<fx:Script>
<![CDATA[
+ import org.apache.flex.createjs.tween.Ease;
import org.apache.flex.createjs.tween.Tween;
import org.apache.flex.createjs.tween.Sequence;
@@ -37,11 +38,13 @@ limitations under the License.
var move1:Tween = new Tween(circle);
move1.xTo = 400;
move1.duration = 1000;
+ move1.easing = Ease.getPowInOut(4);
var move2:Tween = new Tween(circle);
move2.alphaTo = 0;
move2.yTo = 175;
move2.duration = 500;
+ move2.easing = Ease.getPowInOut(2);
var move3:Tween = new Tween(circle);
move3.alphaTo = 0;
@@ -52,10 +55,12 @@ limitations under the License.
move4.alphaTo = 1;
move4.yTo = 200;
move4.duration = 500;
+ move4.easing = Ease.getPowInOut(2);
var move5:Tween = new Tween(circle);
move5.xTo = 100;
move5.duration = 800;
+ move5.easing = Ease.getPowInOut(2);
var seq:Sequence = new Sequence(circle);
seq.loop = true;
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1d424cbf/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as b/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as
index 74a4df6..92a4906 100644
--- a/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as
+++ b/frameworks/projects/CreateJS/src/main/flex/CreateJSClasses.as
@@ -30,6 +30,7 @@ internal class CreateJSClasses
import org.apache.flex.createjs.core.UIBase; UIBase;
import org.apache.flex.createjs.core.View; View;
import org.apache.flex.createjs.graphics.GraphicShape; GraphicShape;
+ import org.apache.flex.createjs.tween.Ease; Ease;
import org.apache.flex.createjs.tween.Tween; Tween;
import org.apache.flex.createjs.tween.Sequence; Sequence;
}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1d424cbf/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Ease.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Ease.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Ease.as
new file mode 100644
index 0000000..20d9763
--- /dev/null
+++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Ease.as
@@ -0,0 +1,672 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.createjs.tween
+{
+ COMPILE::JS {
+ import createjs.Stage;
+ import createjs.Ease;
+ }
+
+ /**
+ * This is the base class for the CreateJS/TweenJS effects.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public class Ease
+ {
+ /**
+ * Constructor
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function Ease()
+ {
+ }
+
+ /**
+ * Mimics the simple -100 to 100 easing in Flash Pro.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ static public function get(value:Number) : Function
+ {
+ COMPILE::AS3 {
+ return null;
+ }
+ COMPILE::JS {
+ return createjs.Ease.get(value);
+ }
+ }
+
+ /**
+ * Configurable exponential ease.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ static public function getPowIn(value:Number) : Function
+ {
+ COMPILE::AS3 {
+ return null;
+ }
+ COMPILE::JS {
+ return createjs.Ease.getPowIn(value);
+ }
+ }
+
+ /**
+ * Configurable exponential ease.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ static public function getPowOut(value:Number) : Function
+ {
+ COMPILE::AS3 {
+ return null;
+ }
+ COMPILE::JS {
+ return createjs.Ease.getPowOut(value);
+ }
+ }
+
+ /**
+ * Configurable exponential ease.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ static public function getPowInOut(value:Number) : Function
+ {
+ COMPILE::AS3 {
+ return null;
+ }
+ COMPILE::JS {
+ return createjs.Ease.getPowInOut(value);
+ }
+ }
+
+ /**
+ * @method quadIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quadIn() : Function
+ {
+ return getPowIn(2);
+ }
+
+ /**
+ * @method quadOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quadOut() : Function
+ {
+ return getPowOut(2);
+ }
+
+ /**
+ * @method quadInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quadInOut() : Function
+ {
+ return getPowInOut(2);
+ }
+
+ /**
+ * @method cubicIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function cubicIn() : Function
+ {
+ return getPowIn(3);
+ }
+
+ /**
+ * @method cubicOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function cubicOut() : Function
+ {
+ return getPowOut(3);
+ }
+
+ /**
+ * @method cubicInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function cubicInOut() : Function
+ {
+ return getPowInOut(3);
+ }
+
+ /**
+ * @method quartIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quartIn() : Function
+ {
+ return getPowIn(4);
+ }
+
+ /**
+ * @method quartOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quartOut() : Function
+ {
+ return getPowOut(4);
+ }
+
+ /**
+ * @method quartInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quartInOut() : Function
+ {
+ return getPowInOut(4);
+ }
+
+ /**
+ * @method quintIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quintIn() : Function
+ {
+ return getPowIn(5);
+ }
+
+ /**
+ * @method quintOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quintOut() : Function
+ {
+ return getPowOut(5);
+ }
+
+ /**
+ * @method quintInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function quintInOut() : Function
+ {
+ return getPowInOut(5);
+ }
+
+ /**
+ * @method sineIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function sineIn(t:Number):Number {
+ return 1-Math.cos(t*Math.PI/2);
+ }
+
+ /**
+ * @method sineOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function sineOut(t:Number):Number {
+ return Math.sin(t*Math.PI/2);
+ }
+
+
+ /**
+ * @method sineInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function sineInOut(t:Number):Number {
+ return -0.5*(Math.cos(Math.PI*t) - 1);
+ }
+
+ /**
+ * Configurable "back in" ease.
+ * @method getBackIn
+ * @param {Number} amount The strength of the ease.
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getBackIn(amount:Number):Function {
+ return function(t:Number):Number {
+ return t*t*((amount+1)*t-amount);
+ }
+ }
+
+ /**
+ * @method backIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function backIn():Function {
+ return getBackIn(1.7);
+ }
+
+ /**
+ * Configurable "back out" ease.
+ * @method getBackOut
+ * @param {Number} amount The strength of the ease.
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getBackOut(amount:Number):Function {
+ return function(t:Number):Number {
+ return (--t*t*((amount+1)*t + amount) + 1);
+ }
+ }
+
+ /**
+ * @method backOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function backOut():Function {
+ return getBackOut(1.7);
+ }
+
+
+ /**
+ * Configurable "back in out" ease.
+ * @method getBackInOut
+ * @param {Number} amount The strength of the ease.
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getBackInOut(amount:Number):Function {
+ amount *= 1.525;
+ return function(t:Number):Number {
+ if ((t*=2)<1) return 0.5*(t*t*((amount+1)*t-amount));
+ return 0.5*((t-=2)*t*((amount+1)*t+amount)+2);
+ }
+ }
+
+ /**
+ * @method backInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function backInOut():Function {
+ return getBackInOut(1.7);
+ }
+
+ /**
+ * @method circIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function circIn(t:Number):Number {
+ return -(Math.sqrt(1-t*t)-1);
+ }
+
+ /**
+ * @method circOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function circOut(t:Number):Number {
+ return Math.sqrt(1-(--t)*t);
+ }
+
+ /**
+ * @method circInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function circInOut(t:Number):Number {
+ if ((t*=2) < 1) return -0.5*(Math.sqrt(1-t*t)-1);
+ return 0.5*(Math.sqrt(1-(t-=2)*t)+1);
+ }
+
+ /**
+ * @method bounceIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function bounceIn(t:Number):Number {
+ return 1-bounceOut(1-t);
+ }
+
+ /**
+ * @method bounceOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ public static function bounceOut(t:Number):Number {
+ if (t < 1/2.75) {
+ return (7.5625*t*t);
+ } else if (t < 2/2.75) {
+ return (7.5625*(t-=1.5/2.75)*t+0.75);
+ } else if (t < 2.5/2.75) {
+ return (7.5625*(t-=2.25/2.75)*t+0.9375);
+ } else {
+ return (7.5625*(t-=2.625/2.75)*t +0.984375);
+ }
+ }
+
+ /**
+ * @method bounceInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function bounceInOut(t:Number):Number
+ {
+ if (t<0.5) return bounceIn (t*2) * .5;
+ return bounceOut(t*2-1)*0.5+0.5;
+ }
+
+ /**
+ * Configurable elastic ease.
+ * @method getElasticIn
+ * @param {Number} amplitude
+ * @param {Number} period
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getElasticIn(amplitude:Number,period:Number):Function {
+ var pi2:Number = Math.PI*2;
+ return function(t:Number):Number {
+ if (t==0 || t==1) return t;
+ var s:Number = period/pi2*Math.asin(1/amplitude);
+ return -(amplitude*Math.pow(2,10*(t-=1))*Math.sin((t-s)*pi2/period));
+ };
+ }
+
+ /**
+ * @method elasticIn
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function elasticIn():Function {
+ return getElasticIn(1,0.3);
+ }
+
+ /**
+ * Configurable elastic ease.
+ * @method getElasticOut
+ * @param {Number} amplitude
+ * @param {Number} period
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getElasticOut(amplitude:Number,period:Number):Function {
+ var pi2:Number = Math.PI*2;
+ return function(t:Number):Number {
+ if (t==0 || t==1) return t;
+ var s:Number = period/pi2 * Math.asin(1/amplitude);
+ return (amplitude*Math.pow(2,-10*t)*Math.sin((t-s)*pi2/period )+1);
+ };
+ }
+
+ /**
+ * @method elasticOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function elasticOut():Function {
+ return getElasticOut(1,0.3);
+ }
+
+ /**
+ * Configurable elastic ease.
+ * @method getElasticInOut
+ * @param {Number} amplitude
+ * @param {Number} period
+ * @static
+ * @return {Function}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function getElasticInOut(amplitude:Number,period:Number):Function {
+ var pi2:Number = Math.PI*2;
+ return function(t:Number):Number {
+ var s:Number = period/pi2 * Math.asin(1/amplitude);
+ if ((t*=2)<1) return -0.5*(amplitude*Math.pow(2,10*(t-=1))*Math.sin( (t-s)*pi2/period ));
+ return amplitude*Math.pow(2,-10*(t-=1))*Math.sin((t-s)*pi2/period)*0.5+1;
+ };
+ }
+
+ /**
+ * @method elasticInOut
+ * @param {Number} t
+ * @static
+ * @return {Number}
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ **/
+ static public function elasticInOut():Function {
+ return getElasticInOut(1,0.3*1.5);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1d424cbf/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Effect.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Effect.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Effect.as
index 21686fb..54e1a3b 100644
--- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Effect.as
+++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Effect.as
@@ -114,6 +114,16 @@ package org.apache.flex.createjs.tween
public var loop:Boolean = false;
/**
+ * The easing function to apply.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public var easing:Function = null;
+
+ /**
* @private
* Returns the options necessary for an effect to take place. This is an
* internally used function.
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1d424cbf/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Sequence.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Sequence.as b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Sequence.as
index 3e5cd6f..9d3bd89 100644
--- a/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Sequence.as
+++ b/frameworks/projects/CreateJS/src/main/flex/org/apache/flex/createjs/tween/Sequence.as
@@ -80,10 +80,14 @@ package org.apache.flex.createjs.tween
_tween = createjs.Tween.get(element, {loop: loop});
_tween.setPaused(true);
+ if (easing == null) {
+ easing = org.apache.flex.createjs.tween.Ease.getPowInOut(2);
+ }
+
for (var i:int=0; i < _tweens.length; i++) {
var e:Effect = _tweens[i] as Effect;
var options:Object = e.createTweenOptions();
- _tween.to( options, e.duration, createjs.Ease.getPowInOut(2));
+ _tween.to( options, e.duration, easing);
}
_tween.setPaused(false);