Fixes for elastic easing functions - but they're still broken

feature/coffeescript
Sven Slootweg 10 years ago
parent 7cf000ce21
commit 85658ad24b

@ -247,7 +247,7 @@
})(); })();
Engine.prototype.ease = { Engine.prototype.ease = {
_calculateElasticValues: function(amplitude, period, change, inout) { _calculateElasticValues: function(duration, amplitude, period, change, inout) {
var overshoot; var overshoot;
if (inout == null) { if (inout == null) {
inout = false; inout = false;
@ -322,7 +322,6 @@
if (invert_repeat == null) { if (invert_repeat == null) {
invert_repeat = false; invert_repeat = false;
} }
console.log("this", this.engine);
return new Ease(this.engine, "bounceOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next); return new Ease(this.engine, "bounceOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next);
}, },
bounceIn: function(start, end, duration, next, infinite, invert_repeat) { bounceIn: function(start, end, duration, next, infinite, invert_repeat) {
@ -438,7 +437,7 @@
if (period == null) { if (period == null) {
period = null; period = null;
} }
_ref = this._calculateElasticValues(amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3]; _ref = this._calculateElasticValues(duration, amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
end = start + change; end = start + change;
return new Ease(this.engine, "elasticOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot); return new Ease(this.engine, "elasticOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
}, },
@ -459,7 +458,7 @@
if (period == null) { if (period == null) {
period = null; period = null;
} }
_ref = this._calculateElasticValues(amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3]; _ref = this._calculateElasticValues(duration, amplitude, period, end - start), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
end = start + change; end = start + change;
return new Ease(this.engine, "elasticIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot); return new Ease(this.engine, "elasticIn", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
}, },
@ -480,7 +479,7 @@
if (period == null) { if (period == null) {
period = null; period = null;
} }
_ref = this._calculateElasticValues(amplitude, period, end - start, true), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3]; _ref = this._calculateElasticValues(duration, amplitude, period, end - start, true), amplitude = _ref[0], period = _ref[1], change = _ref[2], overshoot = _ref[3];
end = start + change; end = start + change;
return new Ease(this.engine, "elasticInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot); return new Ease(this.engine, "elasticInOut", infinite, start, end, this.engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot);
}, },
@ -852,7 +851,7 @@
}; };
Ease.prototype.cubicInOut = function(time) { Ease.prototype.cubicInOut = function(time) {
time = time / (duration / 2); time = time / (this.duration / 2);
if (time < 1) { if (time < 1) {
return change / 2 * time * time * time + this.start; return change / 2 * time * time * time + this.start;
} else { } else {
@ -863,7 +862,7 @@
Ease.prototype.elasticOut = function(time) { Ease.prototype.elasticOut = function(time) {
var amplitude, overshoot, period; var amplitude, overshoot, period;
time = time / duration; time = time / this.duration;
amplitude = this.params[0]; amplitude = this.params[0];
period = this.params[1]; period = this.params[1];
overshoot = this.params[2]; overshoot = this.params[2];
@ -872,7 +871,7 @@
Ease.prototype.elasticIn = function(time) { Ease.prototype.elasticIn = function(time) {
var amplitude, overshoot, period; var amplitude, overshoot, period;
time = time / duration; time = time / this.duration;
amplitude = this.params[0]; amplitude = this.params[0];
period = this.params[1]; period = this.params[1];
overshoot = this.params[2]; overshoot = this.params[2];
@ -881,7 +880,7 @@
Ease.prototype.elasticInOut = function(time) { Ease.prototype.elasticInOut = function(time) {
var amplitude, overshoot, period; var amplitude, overshoot, period;
time = time / (duration / 2) - 1; time = time / (this.duration / 2) - 1;
amplitude = this.params[0]; amplitude = this.params[0];
period = this.params[1]; period = this.params[1];
overshoot = this.params[2]; overshoot = this.params[2];

@ -1,5 +1,5 @@
Engine::ease = Engine::ease =
_calculateElasticValues: (amplitude, period, change, inout = false) -> _calculateElasticValues: (duration, amplitude, period, change, inout = false) ->
if !period? if !period?
if inout if inout
period = duration * (0.3 * 1.5) period = duration * (0.3 * 1.5)
@ -21,7 +21,6 @@ Engine::ease =
backInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, overshoot = 1.70158) -> backInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, overshoot = 1.70158) ->
return new Ease(this.engine, "backInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, overshoot) return new Ease(this.engine, "backInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, overshoot)
bounceOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) -> bounceOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) ->
console.log("this", this.engine)
return new Ease(this.engine, "bounceOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next) return new Ease(this.engine, "bounceOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next)
bounceIn: (start, end, duration, next = null, infinite = false , invert_repeat = false) -> bounceIn: (start, end, duration, next = null, infinite = false , invert_repeat = false) ->
return new Ease(this.engine, "bounceIn", infinite, start, end, @engine.current_frame, duration, invert_repeat, next) return new Ease(this.engine, "bounceIn", infinite, start, end, @engine.current_frame, duration, invert_repeat, next)
@ -40,15 +39,15 @@ Engine::ease =
cubicInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) -> cubicInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) ->
return new Ease(this.engine, "cubicInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next) return new Ease(this.engine, "cubicInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next)
elasticOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) -> elasticOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) ->
[amplitude, period, change, overshoot] = @_calculateElasticValues(amplitude, period, end - start) [amplitude, period, change, overshoot] = @_calculateElasticValues(duration, amplitude, period, end - start)
end = start + change end = start + change
return new Ease(this.engine, "elasticOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot) return new Ease(this.engine, "elasticOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot)
elasticIn: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) -> elasticIn: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) ->
[amplitude, period, change, overshoot] = @_calculateElasticValues(amplitude, period, end - start) [amplitude, period, change, overshoot] = @_calculateElasticValues(duration, amplitude, period, end - start)
end = start + change end = start + change
return new Ease(this.engine, "elasticIn", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot) return new Ease(this.engine, "elasticIn", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot)
elasticInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) -> elasticInOut: (start, end, duration, next = null, infinite = false , invert_repeat = false, amplitude = null, period = null) ->
[amplitude, period, change, overshoot] = @_calculateElasticValues(amplitude, period, end - start, true) [amplitude, period, change, overshoot] = @_calculateElasticValues(duration, amplitude, period, end - start, true)
end = start + change end = start + change
return new Ease(this.engine, "elasticInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot) return new Ease(this.engine, "elasticInOut", infinite, start, end, @engine.current_frame, duration, invert_repeat, next, amplitude, period, overshoot)
expoOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) -> expoOut: (start, end, duration, next = null, infinite = false , invert_repeat = false) ->
@ -207,7 +206,7 @@ class Ease
return @change * (time * time * time + 1) + @start return @change * (time * time * time + 1) + @start
cubicInOut: (time) => cubicInOut: (time) =>
time = time / (duration / 2) time = time / (@duration / 2)
if time < 1 if time < 1
return change / 2 * time * time * time + @start return change / 2 * time * time * time + @start
else else
@ -215,7 +214,7 @@ class Ease
return change / 2 * (time * time * time + 2) + begin return change / 2 * (time * time * time + 2) + begin
elasticOut: (time) => elasticOut: (time) =>
time = time / duration time = time / @duration
amplitude = @params[0] amplitude = @params[0]
period = @params[1] period = @params[1]
overshoot = @params[2] overshoot = @params[2]
@ -223,7 +222,7 @@ class Ease
return (amplitude * Math.pow(2, -10 * time)) * Math.sin((time * @duration - overshoot) * (2 * Math.PI) / period) + @change + @start return (amplitude * Math.pow(2, -10 * time)) * Math.sin((time * @duration - overshoot) * (2 * Math.PI) / period) + @change + @start
elasticIn: (time) => elasticIn: (time) =>
time = time / duration time = time / @duration
amplitude = @params[0] amplitude = @params[0]
period = @params[1] period = @params[1]
overshoot = @params[2] overshoot = @params[2]
@ -231,7 +230,7 @@ class Ease
return -(amplitude * Math.pow(2, -10 * time)) * Math.sin((time * @duration - overshoot) * (2 * Math.PI) / period) + @start return -(amplitude * Math.pow(2, -10 * time)) * Math.sin((time * @duration - overshoot) * (2 * Math.PI) / period) + @start
elasticInOut: (time) => elasticInOut: (time) =>
time = time / (duration / 2) - 1 time = time / (@duration / 2) - 1
amplitude = @params[0] amplitude = @params[0]
period = @params[1] period = @params[1]
overshoot = @params[2] overshoot = @params[2]

Loading…
Cancel
Save