From 09be19b428e39acf26ef2e2d02baea12553e604a Mon Sep 17 00:00:00 2001 From: Peter Hoddie Date: Mon, 19 Feb 2024 17:54:39 -0800 Subject: [PATCH] split easing equations out from Piu for more general uses #1309 --- examples/manifest_piu.json | 3 + modules/base/easing/easing.c | 342 ++++++++++++++++++++++++++++++ modules/base/easing/easing.js | 45 ++++ modules/base/easing/manifest.json | 6 + modules/piu/All/piuAll.js | 34 +-- modules/piu/All/piuTransition.c | 323 +--------------------------- tools/mcsim/manifest.json | 3 + tools/xsbug/manifest.json | 3 + 8 files changed, 404 insertions(+), 355 deletions(-) create mode 100644 modules/base/easing/easing.c create mode 100644 modules/base/easing/easing.js create mode 100644 modules/base/easing/manifest.json diff --git a/examples/manifest_piu.json b/examples/manifest_piu.json index 4cf7956c69..3e61c69aab 100644 --- a/examples/manifest_piu.json +++ b/examples/manifest_piu.json @@ -1,4 +1,7 @@ { + "include": [ + "$(MODULES)/base/easing/manifest.json" + ], "modules": { "commodetto/Bitmap": "$(COMMODETTO)/commodettoBitmap", "commodetto/PocoCore": "$(COMMODETTO)/commodettoPocoCore", diff --git a/modules/base/easing/easing.c b/modules/base/easing/easing.c new file mode 100644 index 0000000000..340b63d117 --- /dev/null +++ b/modules/base/easing/easing.c @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2016-2024 Moddable Tech, Inc. + * + * This file is part of the Moddable SDK Runtime. + * + * The Moddable SDK Runtime is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Moddable SDK Runtime is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Moddable SDK Runtime. If not, see . + * + */ + +#include "mc.xs.h" +#include "xsHost.h" + +void Math_quadEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(fraction * fraction); +} + +void Math_quadEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(-1 * fraction * (fraction - 2)); +} + +void Math_quadEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber(fraction * fraction / 2); + else { + fraction -= 1; + xsResult = xsNumber((fraction * (fraction - 2) - 1) / -2); + } +} + +void Math_cubicEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(fraction * fraction * fraction); +} + +void Math_cubicEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + double f = fraction - 1; + xsResult = xsNumber(f * f * f + 1); +} + +void Math_cubicEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber(fraction * fraction * fraction / 2); + else { + fraction -= 2; + xsResult = xsNumber((fraction * fraction * fraction + 2) / 2); + } +} + +void Math_quartEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(fraction * fraction * fraction * fraction); +} + +void Math_quartEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + double f = fraction - 1; + xsResult = xsNumber(-1 * (f * f * f * f - 1)); +} + +void Math_quartEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber(fraction * fraction * fraction * fraction / 2); + else { + fraction -= 2; + xsResult = xsNumber((fraction * fraction * fraction * fraction - 2) / -2); + } +} + +void Math_quintEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(fraction * fraction * fraction * fraction * fraction); +} + +void Math_quintEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + double f = fraction - 1; + xsResult = xsNumber(f * f * f * f * f + 1); +} + +void Math_quintEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber(fraction * fraction * fraction * fraction * fraction / 2); + else { + fraction -= 2; + xsResult = xsNumber((fraction * fraction * fraction * fraction * fraction + 2) / 2); + } +} + +void Math_sineEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(-1 * cos(fraction * (C_M_PI / 2)) + 1); +} + +void Math_sineEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(sin(fraction * (C_M_PI / 2))); +} + +void Math_sineEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(-1.0 / 2.0 * (cos(C_M_PI * fraction) - 1)); +} + +void Math_circularEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(-1 * (sqrt(1 - fraction * fraction) - 1)); +} + +void Math_circularEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction -= 1; + xsResult = xsNumber(sqrt(1 - fraction * fraction)); +} + +void Math_circularEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber((sqrt(1 - fraction * fraction) - 1) / -2); + else { + fraction -= 2; + xsResult = xsNumber((sqrt(1 - fraction * fraction) + 1) / 2); + } +} + +void Math_exponentialEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber((fraction == 0) ? 0 : pow(2, 10 * (fraction - 1))); +} + +void Math_exponentialEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber((fraction == 1) ? 1 : (-pow(2, -10 * fraction) + 1)); +} + +void Math_exponentialEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + if (fraction == 0) + xsResult = xsNumber(0); + else if (fraction == 1) + xsResult = xsNumber(1); + else { + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber(pow(2, 10 * (fraction - 1)) / 2); + else + xsResult = xsNumber((-pow(2, -10 * --fraction) + 2) / 2); + } +} + +void Math_backEaseIn(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; + xsResult = xsNumber(fraction * fraction * ((s + 1) * fraction - s)); +} + +void Math_backEaseOut(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; + fraction -= 1; + xsResult = xsNumber(fraction * fraction * ((s + 1) * fraction + s) + 1); +} + +void Math_backEaseInOut(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; + s *= 1.525; + fraction *= 2; + if (fraction < 1) + xsResult = xsNumber((fraction * fraction * (s + 1) * fraction - s) / 2); + else { + fraction -= 2; + xsResult = xsNumber((fraction * fraction * ((s + 1) * fraction + s) + 2) / 2); + } +} + +static double bounce(double fraction) +{ + if (fraction < (1 / 2.75)) + fraction = 7.5625 * fraction * fraction; + else if (fraction < (2 / 2.75)) { + fraction -= (1.5 / 2.75); + fraction = 7.5625 * fraction * fraction + 0.75; + } + else if (fraction < (2.5 / 2.75)) { + fraction -= (2.25 / 2.75); + fraction = 7.5625 * fraction * fraction + 0.9375; + } + else { + fraction -= (2.625 / 2.75); + fraction = 7.5625 * fraction * fraction + 0.984375; + } + return fraction; +} + +void Math_bounceEaseIn(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(1 - bounce(1 - fraction)); +} + +void Math_bounceEaseOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + xsResult = xsNumber(bounce(fraction)); +} + +void Math_bounceEaseInOut(xsMachine* the) +{ + double fraction = xsToNumber(xsArg(0)); + if (fraction < 0.5) + xsResult = xsNumber((1 - bounce(1 - (fraction * 2))) / 2); + else + xsResult = xsNumber(bounce(fraction * 2 - 1) / 2 + 0.5); +} + +void Math_elasticEaseIn(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + if (fraction == 0) + xsResult = xsNumber(0); + else if (fraction == 1) + xsResult = xsNumber(1); + else { + double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; + double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; + double s; + if (!p) + p = 0.3; + if (a < 1) { + a = 1; + s = p / 4; + } + else + s = p / (2 * C_M_PI) * asin(1 / a); + fraction -= 1; + xsResult = xsNumber(-(a * pow(2, 10 * fraction) * sin( (fraction - s) * (2 * C_M_PI) / p ))); + } +} + +void Math_elasticEaseOut(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + if (fraction == 0) + xsResult = xsNumber(0); + else if (fraction == 1) + xsResult = xsNumber(1); + else { + double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; + double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; + double s; + if (!p) + p = 0.3; + if (a < 1) { + a = 1; + s = p / 4; + } + else + s = p / (2 * C_M_PI) * asin(1 / a); + xsResult = xsNumber(a * pow(2, -10 * fraction ) * sin((fraction - s) * (2 * C_M_PI) / p ) + 1); + } +} + +void Math_elasticEaseInOut(xsMachine* the) +{ + xsIntegerValue c = xsToInteger(xsArgc); + double fraction = xsToNumber(xsArg(0)); + if (fraction == 0) + xsResult = xsNumber(0); + else if (fraction == 1) + xsResult = xsNumber(1); + else { + double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; + double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; + double s; + fraction *= 2; + if (!p) + p = 0.45; + if (a < 1) { + a = 1; + s = p / 4; + } + else + s = p / (2 * C_M_PI) * asin(1 / a); + fraction -= 1; + if (fraction < 0) + xsResult = xsNumber((a * pow(2, 10 * fraction) * sin((fraction - s) * (2 * C_M_PI) / p )) / -2); + else + xsResult = xsNumber(a * pow(2, -10 * fraction) * sin((fraction - s) * 2 * C_M_PI / p ) / 2 + 1); + } +} diff --git a/modules/base/easing/easing.js b/modules/base/easing/easing.js new file mode 100644 index 0000000000..69b690a675 --- /dev/null +++ b/modules/base/easing/easing.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016-2024 Moddable Tech, Inc. + * + * This file is part of the Moddable SDK. + * + * This work is licensed under the + * Creative Commons Attribution 4.0 International License. + * To view a copy of this license, visit + * . + * or send a letter to Creative Commons, PO Box 1866, + * Mountain View, CA 94042, USA. + * + */ + +Math.backEaseIn = function(fraction) @ "Math_backEaseIn"; +Math.backEaseInOut = function(fraction) @ "Math_backEaseInOut"; +Math.backEaseOut = function(fraction) @ "Math_backEaseOut"; +Math.bounceEaseIn = function(fraction) @ "Math_bounceEaseIn"; +Math.bounceEaseInOut = function(fraction) @ "Math_bounceEaseInOut"; +Math.bounceEaseOut = function(fraction) @ "Math_bounceEaseOut"; +Math.circularEaseIn = function(fraction) @ "Math_circularEaseIn"; +Math.circularEaseInOut = function(fraction) @ "Math_circularEaseInOut"; +Math.circularEaseOut = function(fraction) @ "Math_circularEaseOut"; +Math.cubicEaseIn = function(fraction) @ "Math_cubicEaseIn"; +Math.cubicEaseInOut = function(fraction) @ "Math_cubicEaseInOut"; +Math.cubicEaseOut = function(fraction) @ "Math_cubicEaseOut"; +Math.elasticEaseIn = function(fraction) @ "Math_elasticEaseIn"; +Math.elasticEaseInOut = function(fraction) @ "Math_elasticEaseInOut"; +Math.elasticEaseOut = function(fraction) @ "Math_elasticEaseOut"; +Math.exponentialEaseIn = function(fraction) @ "Math_exponentialEaseIn"; +Math.exponentialEaseInOut = function(fraction) @ "Math_exponentialEaseInOut"; +Math.exponentialEaseOut = function(fraction) @ "Math_exponentialEaseOut"; +Math.quadEaseIn = function(fraction) @ "Math_quadEaseIn"; +Math.quadEaseInOut = function(fraction) @ "Math_quadEaseInOut"; +Math.quadEaseOut = function(fraction) @ "Math_quadEaseOut"; +Math.quartEaseIn = function(fraction) @ "Math_quartEaseIn"; +Math.quartEaseInOut = function(fraction) @ "Math_quartEaseInOut"; +Math.quartEaseOut = function(fraction) @ "Math_quartEaseOut"; +Math.quintEaseIn = function(fraction) @ "Math_quintEaseIn"; +Math.quintEaseInOut = function(fraction) @ "Math_quintEaseInOut"; +Math.quintEaseOut = function(fraction) @ "Math_quintEaseOut"; +Math.sineEaseIn = function(fraction) @ "Math_sineEaseIn"; +Math.sineEaseInOut = function(fraction) @ "Math_sineEaseInOut"; +Math.sineEaseOut = function(fraction) @ "Math_sineEaseOut"; + diff --git a/modules/base/easing/manifest.json b/modules/base/easing/manifest.json new file mode 100644 index 0000000000..82e26e4f5e --- /dev/null +++ b/modules/base/easing/manifest.json @@ -0,0 +1,6 @@ +{ + "modules": { + "*": "./easing" + }, + "preload": "easing" +} diff --git a/modules/piu/All/piuAll.js b/modules/piu/All/piuAll.js index 437fcfe893..d181762d2c 100644 --- a/modules/piu/All/piuAll.js +++ b/modules/piu/All/piuAll.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Moddable Tech, Inc. + * Copyright (c) 2016-2024 Moddable Tech, Inc. * * This file is part of the Moddable SDK Runtime. * @@ -456,35 +456,3 @@ export class Locals @ "PiuLocalsDelete" { } Object.freeze(Locals.prototype); global.Locals = Locals; - -Math.backEaseIn = function(fraction) @ "Math_backEaseIn"; -Math.backEaseInOut = function(fraction) @ "Math_backEaseInOut"; -Math.backEaseOut = function(fraction) @ "Math_backEaseOut"; -Math.bounceEaseIn = function(fraction) @ "Math_bounceEaseIn"; -Math.bounceEaseInOut = function(fraction) @ "Math_bounceEaseInOut"; -Math.bounceEaseOut = function(fraction) @ "Math_bounceEaseOut"; -Math.circularEaseIn = function(fraction) @ "Math_circularEaseIn"; -Math.circularEaseInOut = function(fraction) @ "Math_circularEaseInOut"; -Math.circularEaseOut = function(fraction) @ "Math_circularEaseOut"; -Math.cubicEaseIn = function(fraction) @ "Math_cubicEaseIn"; -Math.cubicEaseInOut = function(fraction) @ "Math_cubicEaseInOut"; -Math.cubicEaseOut = function(fraction) @ "Math_cubicEaseOut"; -Math.elasticEaseIn = function(fraction) @ "Math_elasticEaseIn"; -Math.elasticEaseInOut = function(fraction) @ "Math_elasticEaseInOut"; -Math.elasticEaseOut = function(fraction) @ "Math_elasticEaseOut"; -Math.exponentialEaseIn = function(fraction) @ "Math_exponentialEaseIn"; -Math.exponentialEaseInOut = function(fraction) @ "Math_exponentialEaseInOut"; -Math.exponentialEaseOut = function(fraction) @ "Math_exponentialEaseOut"; -Math.quadEaseIn = function(fraction) @ "Math_quadEaseIn"; -Math.quadEaseInOut = function(fraction) @ "Math_quadEaseInOut"; -Math.quadEaseOut = function(fraction) @ "Math_quadEaseOut"; -Math.quartEaseIn = function(fraction) @ "Math_quartEaseIn"; -Math.quartEaseInOut = function(fraction) @ "Math_quartEaseInOut"; -Math.quartEaseOut = function(fraction) @ "Math_quartEaseOut"; -Math.quintEaseIn = function(fraction) @ "Math_quintEaseIn"; -Math.quintEaseInOut = function(fraction) @ "Math_quintEaseInOut"; -Math.quintEaseOut = function(fraction) @ "Math_quintEaseOut"; -Math.sineEaseIn = function(fraction) @ "Math_sineEaseIn"; -Math.sineEaseInOut = function(fraction) @ "Math_sineEaseInOut"; -Math.sineEaseOut = function(fraction) @ "Math_sineEaseOut"; - diff --git a/modules/piu/All/piuTransition.c b/modules/piu/All/piuTransition.c index 8aa96c4cd5..56d84d8857 100644 --- a/modules/piu/All/piuTransition.c +++ b/modules/piu/All/piuTransition.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2017 Moddable Tech, Inc. + * Copyright (c) 2016-2024 Moddable Tech, Inc. * * This file is part of the Moddable SDK Runtime. * @@ -196,324 +196,3 @@ void PiuTransition_set_duration(xsMachine *the) duration = 0; (*self)->duration = duration; } - -void Math_quadEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(fraction * fraction); -} - -void Math_quadEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(-1 * fraction * (fraction - 2)); -} - -void Math_quadEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber(fraction * fraction / 2); - else { - fraction -= 1; - xsResult = xsNumber((fraction * (fraction - 2) - 1) / -2); - } -} - -void Math_cubicEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(fraction * fraction * fraction); -} - -void Math_cubicEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - double f = fraction - 1; - xsResult = xsNumber(f * f * f + 1); -} - -void Math_cubicEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber(fraction * fraction * fraction / 2); - else { - fraction -= 2; - xsResult = xsNumber((fraction * fraction * fraction + 2) / 2); - } -} - -void Math_quartEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(fraction * fraction * fraction * fraction); -} - -void Math_quartEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - double f = fraction - 1; - xsResult = xsNumber(-1 * (f * f * f * f - 1)); -} - -void Math_quartEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber(fraction * fraction * fraction * fraction / 2); - else { - fraction -= 2; - xsResult = xsNumber((fraction * fraction * fraction * fraction - 2) / -2); - } -} - -void Math_quintEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(fraction * fraction * fraction * fraction * fraction); -} - -void Math_quintEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - double f = fraction - 1; - xsResult = xsNumber(f * f * f * f * f + 1); -} - -void Math_quintEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber(fraction * fraction * fraction * fraction * fraction / 2); - else { - fraction -= 2; - xsResult = xsNumber((fraction * fraction * fraction * fraction * fraction + 2) / 2); - } -} - -void Math_sineEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(-1 * cos(fraction * (C_M_PI / 2)) + 1); -} - -void Math_sineEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(sin(fraction * (C_M_PI / 2))); -} - -void Math_sineEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(-1.0 / 2.0 * (cos(C_M_PI * fraction) - 1)); -} - -void Math_circularEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(-1 * (sqrt(1 - fraction * fraction) - 1)); -} - -void Math_circularEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction -= 1; - xsResult = xsNumber(sqrt(1 - fraction * fraction)); -} - -void Math_circularEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber((sqrt(1 - fraction * fraction) - 1) / -2); - else { - fraction -= 2; - xsResult = xsNumber((sqrt(1 - fraction * fraction) + 1) / 2); - } -} - -void Math_exponentialEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber((fraction == 0) ? 0 : pow(2, 10 * (fraction - 1))); -} - -void Math_exponentialEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber((fraction == 1) ? 1 : (-pow(2, -10 * fraction) + 1)); -} - -void Math_exponentialEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - if (fraction == 0) - xsResult = xsNumber(0); - else if (fraction == 1) - xsResult = xsNumber(1); - else { - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber(pow(2, 10 * (fraction - 1)) / 2); - else - xsResult = xsNumber((-pow(2, -10 * --fraction) + 2) / 2); - } -} - -void Math_backEaseIn(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; - xsResult = xsNumber(fraction * fraction * ((s + 1) * fraction - s)); -} - -void Math_backEaseOut(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; - fraction -= 1; - xsResult = xsNumber(fraction * fraction * ((s + 1) * fraction + s) + 1); -} - -void Math_backEaseInOut(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - double s = (c > 1) ? xsToNumber(xsArg(1)) : 1.70158; - s *= 1.525; - fraction *= 2; - if (fraction < 1) - xsResult = xsNumber((fraction * fraction * (s + 1) * fraction - s) / 2); - else { - fraction -= 2; - xsResult = xsNumber((fraction * fraction * ((s + 1) * fraction + s) + 2) / 2); - } -} - -static double bounce(double fraction) -{ - if (fraction < (1 / 2.75)) - fraction = 7.5625 * fraction * fraction; - else if (fraction < (2 / 2.75)) { - fraction -= (1.5 / 2.75); - fraction = 7.5625 * fraction * fraction + 0.75; - } - else if (fraction < (2.5 / 2.75)) { - fraction -= (2.25 / 2.75); - fraction = 7.5625 * fraction * fraction + 0.9375; - } - else { - fraction -= (2.625 / 2.75); - fraction = 7.5625 * fraction * fraction + 0.984375; - } - return fraction; -} - -void Math_bounceEaseIn(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(1 - bounce(1 - fraction)); -} - -void Math_bounceEaseOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - xsResult = xsNumber(bounce(fraction)); -} - -void Math_bounceEaseInOut(xsMachine* the) -{ - double fraction = xsToNumber(xsArg(0)); - if (fraction < 0.5) - xsResult = xsNumber((1 - bounce(1 - (fraction * 2))) / 2); - else - xsResult = xsNumber(bounce(fraction * 2 - 1) / 2 + 0.5); -} - -void Math_elasticEaseIn(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - if (fraction == 0) - xsResult = xsNumber(0); - else if (fraction == 1) - xsResult = xsNumber(1); - else { - double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; - double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; - double s; - if (!p) - p = 0.3; - if (a < 1) { - a = 1; - s = p / 4; - } - else - s = p / (2 * C_M_PI) * asin(1 / a); - fraction -= 1; - xsResult = xsNumber(-(a * pow(2, 10 * fraction) * sin( (fraction - s) * (2 * C_M_PI) / p ))); - } -} - -void Math_elasticEaseOut(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - if (fraction == 0) - xsResult = xsNumber(0); - else if (fraction == 1) - xsResult = xsNumber(1); - else { - double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; - double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; - double s; - if (!p) - p = 0.3; - if (a < 1) { - a = 1; - s = p / 4; - } - else - s = p / (2 * C_M_PI) * asin(1 / a); - xsResult = xsNumber(a * pow(2, -10 * fraction ) * sin((fraction - s) * (2 * C_M_PI) / p ) + 1); - } -} - -void Math_elasticEaseInOut(xsMachine* the) -{ - xsIntegerValue c = xsToInteger(xsArgc); - double fraction = xsToNumber(xsArg(0)); - if (fraction == 0) - xsResult = xsNumber(0); - else if (fraction == 1) - xsResult = xsNumber(1); - else { - double a = (c > 1) ? xsToNumber(xsArg(1)) : 0; - double p = (c > 2) ? xsToNumber(xsArg(2)) : 0; - double s; - fraction *= 2; - if (!p) - p = 0.45; - if (a < 1) { - a = 1; - s = p / 4; - } - else - s = p / (2 * C_M_PI) * asin(1 / a); - fraction -= 1; - if (fraction < 0) - xsResult = xsNumber((a * pow(2, 10 * fraction) * sin((fraction - s) * (2 * C_M_PI) / p )) / -2); - else - xsResult = xsNumber(a * pow(2, -10 * fraction) * sin((fraction - s) * 2 * C_M_PI / p ) / 2 + 1); - } -} - diff --git a/tools/mcsim/manifest.json b/tools/mcsim/manifest.json index 91c540c2a8..6e67db3c01 100644 --- a/tools/mcsim/manifest.json +++ b/tools/mcsim/manifest.json @@ -26,6 +26,9 @@ "*": [ ] }, + "include": [ + "$(MODULES)/base/easing/manifest.json" + ], "modules": { "~": [ "$(SIMULATOR)/modules/screen" diff --git a/tools/xsbug/manifest.json b/tools/xsbug/manifest.json index 6f1c134b9c..259295262e 100644 --- a/tools/xsbug/manifest.json +++ b/tools/xsbug/manifest.json @@ -24,6 +24,9 @@ "*": [ ] }, + "include": [ + "$(MODULES)/base/easing/manifest.json" + ], "modules": { "~": [ ],