Tween

Tween

Source:
All of functions that related to Tween (see here for more infos)

Methods

(static) berp(time, num1opt, num2opt, num3opt, num4opt) → {number}

Source:
Berp
Example
Tween.berp(0.5);
//1.702349952859165
Parameters:
Name Type Attributes Default Description
time number
num1 number <optional>
0.2
num2 number <optional>
2.5
num3 number <optional>
2.2
num4 number <optional>
1.2
Returns:
Type
number

(static) bezier(time, points, weight) → {number}

Source:
Bezier tween
Example
Tween.bezier(1 / 3, [50, 100, 150, 200], [1, 1, 1, 1]);
//99.99999999999999
Parameters:
Name Type Description
time number
points Array.<number> control points [a, b, ...]
weight Array.<number> weight [a, b, ...]
Returns:
Type
number

(static) bias(time, bias) → {number}

Source:
Bias
Example
Tween.bias(0.5, 2);
//0.3333333333333333
Parameters:
Name Type Description
time number
bias number
Returns:
Type
number

(static) bounce(time, bouncinessopt, elasticityopt, gravityopt, backopt) → {number}

Source:
Bounce
Example
Tween.bounce(0.25);
//0.2331217960505344
Parameters:
Name Type Attributes Default Description
time number
bounciness number <optional>
400
elasticity number <optional>
200
gravity number <optional>
100
back boolean <optional>
false `true` if return back to 0
Returns:
Type
number

(static) bspline(time, degree, dimension, points, knotopt, weightopt, returnDataopt) → {number|Array.<number>}

Source:
Example
Tween.bspline(0.5, 2, 2, [0, 0, 1, 0, 2, 1]);
//[1, 0.125]
Parameters:
Name Type Attributes Description
time number
degree number must be at least 1 and less than or equal to total points - 1
dimension number dimension of control points
points Array.<number> control points [a, b, ...]
knot Array.<number> <optional>
must be non-decreasing and equal to total points + degree + 1
weight Array.<number> <optional>
weight [a, b, ...], length is total points
returnData Array.<number> <optional>
Array to put data
Returns:
Type
number | Array.<number>

(static) count(min, max, change, current, mode) → {count~counter}

Source:
Configurable counting number function
Example
let counter = Tween.count(0, 10, 1, 0, 0);
//counter is now a callable function, you can call it like: counter()
Parameters:
Name Type Description
min number
max number
change number
current number current start number (not minimum)
mode number there are different modes from 0 to 5, you can test it yourself (recommended to use 1 and 3)
Returns:
See `counter` in global for the return function
Type
count~counter

(static) envelope(time, num1opt, num2opt) → {number}

Source:
Envelope
Example
Tween.envelope(0.5);
//1
Parameters:
Name Type Attributes Default Description
time number
num1 number <optional>
0.5 Rise
num2 number <optional>
0.5 Fall
Returns:
Type
number

(static) hspline(continuty, bias, tension, density, points, isLoopopt, isStartopt, returnDataopt) → {Array.<number>}

Source:
Example
Tween.hspline(1, 1, 1, 0.5, [1, 1, 3, 2]);
//[1, 1, 2, 1.5, 3, 2]
Parameters:
Name Type Attributes Default Description
continuty number
bias number
tension number
density number like time
points Array.<number> control points [x1, y1, x2, y2, ...]
isLoop boolean <optional>
false `true` if looped
isStart boolean <optional>
false `true` if include start points
returnData array <optional>
Array to put data
Returns:
Return array of points [x1, y1, x2, y2, ...]
Type
Array.<number>

(static) inBack(time, overShoot, isOver) → {number}

Source:
In Back
Example
Tween.inBack(0.25, 2);
//-0.7024967320129584
Parameters:
Name Type Description
time number
overShoot number
isOver boolean `true` is raw number input
Returns:
Type
number

(static) inBounce(time) → {number}

Source:
In Bounce
Example
Tween.inBounce(0.25);
//0.02734375
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inCirc(time) → {number}

Source:
In Circular
Example
Tween.inCirc(0.25);
//0.031754163448145745
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inCubic(time) → {number}

Source:
In Cubic
Example
Tween.inCubic(0.25);
//0.015625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inElastic(time, amplitude, period) → {number}

Source:
In Elastic
Example
Tween.inElastic(0.25, 2, 2);
//0.0028595734670659252
Parameters:
Name Type Description
time number
amplitude number
period number
Returns:
Type
number

(static) inExpo(time) → {number}

Source:
In Exponent
Example
Tween.inExpo(0.25);
//0.005524271728019903
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inLog(time, pow) → {number}

Source:
In Log
Example
Tween.inLog(0.25, 2);
//0.19264507794239594
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) inOut(time, func) → {number}

Source:
inOut
Example
Tween.inOut(0.25, Tween.inQuad);
//0.125
Parameters:
Name Type Description
time number
func function (x)
Returns:
Type
number

(static) inOutBack(time, overShoot, isOver) → {number}

Source:
In Out Back
Example
Tween.inOutBack(0.25, 2);
//-1.3976808550930153
Parameters:
Name Type Description
time number
overShoot number
isOver boolean `true` if raw number input
Returns:
Type
number

(static) inOutBias(time, bias) → {number}

Source:
In Out Bias
Example
Tween.inOutBias(0.5, 2);
//0.3333333333333333
Parameters:
Name Type Description
time number
bias number
Returns:
Type
number

(static) inOutBounce(time) → {number}

Source:
In Out Bounce
Example
Tween.inOutBounce(0.25);
//0.1171875
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutCirc(time) → {number}

Source:
In Out Circular
Example
Tween.inOutCirc(0.25);
//0.0669872981077807
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutCubic(time) → {number}

Source:
In Out Cubic
Example
Tween.inOutCubic(0.25);
//0.0625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutElastic(time, amplitude, period) → {number}

Source:
In Out Elastic
Example
Tween.inOutElastic(0.25, 2, 2);
//0.027063293868263706
Parameters:
Name Type Description
time number
amplitude number
period number
Returns:
Type
number

(static) inOutExpo(time) → {number}

Source:
In Out Exponent
Example
Tween.inOutExpo(0.25);
//0.015625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutLog(time, pow) → {number}

Source:
In Out Log
Example
Tween.inOutLog(0.25, 2);
//0.2075187496394219
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) inOutPow(time, pow) → {number}

Source:
In Out Pow (same as quad, cubic,... but modifiable exponent)
Example
Tween.inOutPow(0.25, 2);
//0.125
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) inOutQuad(time) → {number}

Source:
In Out Quad
Example
Tween.inOutQuad(0.25);
//0.125
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutQuart(time) → {number}

Source:
In Out Quart
Example
Tween.inOutQuart(0.25);
//0.03125
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutQuint(time) → {number}

Source:
In Out Quint
Example
Tween.inOutQuint(0.25);
//0.015625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inOutSine(time, pow) → {number}

Source:
In Out Sine
Example
Tween.inOutSine(0.25, 1);
//0.49999999999999994
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) inPow(time, pow) → {number}

Source:
In Pow (same as quad, cubic,... but modifiable exponent)
Example
Tween.inPow(0.25, 2);
//0.0625
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) inQuad(time) → {number}

Source:
In Quad
Example
Tween.inQuad(0.25);
//0.0625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inQuart(time) → {number}

Source:
In Quart
Example
Tween.inQuart(0.25);
//0.00390625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inQuint(time) → {number}

Source:
In Quint
Example
Tween.inQuint(0.25);
//0.0009765625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) inSine(time, pow) → {number}

Source:
In Sine
Example
Tween.inSine(0.25, 1);
//0.07612046748871326
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) outBack(time, overShoot, isOver) → {number}

Source:
Out Back
Example
Tween.outBack(0.25, 2);
//2.732490196038875
Parameters:
Name Type Description
time number
overShoot number
isOver boolean `true` is raw number input
Returns:
Type
number

(static) outBounce(time) → {number}

Source:
Out Bounce
Example
Tween.outBounce(0.25);
//0.47265625
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outCirc(time) → {number}

Source:
Out Circular
Example
Tween.outCirc(0.25);
//0.6614378277661477
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outCubic(time) → {number}

Source:
Out Cubic
Example
Tween.outCubic(0.25);
//0.578125
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outElastic(time, amplitude, period) → {number}

Source:
Out Elastic
Example
Tween.outElastic(0.25, 2, 2);
//1.0915063509461096
Parameters:
Name Type Description
time number
amplitude number
period number
Returns:
Type
number

(static) outExpo(time) → {number}

Source:
Out Exponent
Example
Tween.outExpo(0.25);
//0.8232233047033631
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outIn(time, func) → {number}

Source:
outIn
Example
Tween.outIn(0.25, Tween.inQuad);
//0.375
Parameters:
Name Type Description
time number
func function (x)
Returns:
Type
number

(static) outLog(time, pow) → {number}

Source:
Out Log
Example
Tween.outLog(0.25, 2);
//0.32192809488736235
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) outPow(time, pow) → {number}

Source:
Out Pow (same as quad, cubic,... but modifiable exponent)
Example
Tween.outPow(0.25, 2);
//0.4375
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) outQuad(time) → {number}

Source:
Out Quad
Example
Tween.outQuad(0.25);
//0.4375
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outQuart(time) → {number}

Source:
Out Quart
Example
Tween.outQuart(0.25);
//0.68359375
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outQuint(time) → {number}

Source:
Out Quint
Example
Tween.outQuint(0.25);
//0.7626953125
Parameters:
Name Type Description
time number
Returns:
Type
number

(static) outSine(time, pow) → {number}

Source:
Out Sine
Example
Tween.outSine(0.25, 1);
//0.3826834323650898
Parameters:
Name Type Description
time number
pow number exponent
Returns:
Type
number

(static) overShoot(time, mag) → {number}

Source:
Overshoot
Example
Tween.overShoot(0.25, 2);
//1.2956871203528266
Parameters:
Name Type Description
time number
mag number magnitude
Returns:
Type
number

(static) poly(time, points, weight) → {number}

Source:
Polynomial tween
Example
Tween.poly(0.25, [0.25, 0.5], [1, 1]);
//0.5
Parameters:
Name Type Description
time number
points Array.<number> control points [x1, y1, x2, y2, ...]
weight Array.<number> weight of points [a, b, ...]
Returns:
Type
number

(static) reverse(time, func) → {number}

Source:
Reverse
Example
Tween.reverse(0.25, Tween.inQuad);
//0.4375
Parameters:
Name Type Description
time number
func function (x)
Returns:
Type
number

(static) rk4(x, v, dt, hdt, idt, func, returnDataopt) → {Array.<number>}

Source:
Example
Tween.rk4(1, 0, 1 / 50, 0.01, 0.01, function(x, v) {
  //This is the acceleration function
  //This particular one models a spring with a 1kg mass
  var stiffness = 400, damping = 0.25;
  return stiffness * x + damping * v; //may inverse
});
//[1.0827995, 7.979899875]
Parameters:
Name Type Attributes Description
x number initial position
v number initial velocity
dt number timestep
hdt number dt / 2
idt number dt * 2
func function acceleration function (x, v)
returnData Array.<number> <optional>
Array to put data
Returns:
Type
Array.<number>

(static) scale(time, startopt, endopt) → {number}

Source:
Scale
Example
Tween.scale(0.5, 1, 2);
//0.41421356237309515
Parameters:
Name Type Attributes Description
time number
start number <optional>
end number <optional>
Returns:
Type
number

(static) shift(time, left, right) → {number}

Source:
Power shift
Example
Tween.shift(0.5, 1, 1);
//1
Parameters:
Name Type Description
time number
left number shift to left
right number shift to right
Returns:
Type
number

(static) slow(time, ratioopt, poweropt, backopt) → {number}

Source:
Slow
Example
Tween.slow(0.25);
//0.425
Parameters:
Name Type Attributes Default Description
time number
ratio number <optional>
0.7
power number <optional>
0.7
back boolean <optional>
false `true` if return back to 0
Returns:
Type
number

(static) smoothStep(time, order) → {number}

Source:
Example
Tween.smoothStep(0.25, 1);
//0.15625
Parameters:
Name Type Description
time number
order number
Returns:
Type
number

(static) spring(time, frequencyopt, frictionopt, sizeopt, strengthopt, scaleopt) → {number}

Source:
Spring
Example
Tween.spring(0.25);
//1.2447125642905208
Parameters:
Name Type Attributes Default Description
time number
frequency number <optional>
300
friction number <optional>
200
size number <optional>
0
strength number <optional>
0
scale number <optional>
0.8
Returns:
Type
number

(static) wave(frequency, dampen, size, data, value, count, count2opt, gainopt, maxopt) → {number}

Source:
Example
let data = Array(100).fill(0);
Tween.wave(1, 1, 100, data, 1, 0);
//0
//data: [1, 2, 0, 0, 1, 0, 0, 0, 0, ...]
Parameters:
Name Type Attributes Default Description
frequency number
dampen number
size number size
data Array.<number> array of number (if first call then all must be 0), length must be size * size * 3 if 2D, else size * 3
value number update value
count number put increment++ here if 1D, else x position when 2D
count2 number <optional>
y position when 2D
gain number <optional>
100 gain
max number <optional>
10 max value when 2D
Returns:
To get value for 1D: data[i * 3 + return], 2D: data[x * size + y]
Type
number