source: node_modules/d3-ease/src/elastic.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import {tpmt} from "./math.js";
2
3var tau = 2 * Math.PI,
4 amplitude = 1,
5 period = 0.3;
6
7export var elasticIn = (function custom(a, p) {
8 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
9
10 function elasticIn(t) {
11 return a * tpmt(-(--t)) * Math.sin((s - t) / p);
12 }
13
14 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
15 elasticIn.period = function(p) { return custom(a, p); };
16
17 return elasticIn;
18})(amplitude, period);
19
20export var elasticOut = (function custom(a, p) {
21 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
22
23 function elasticOut(t) {
24 return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
25 }
26
27 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
28 elasticOut.period = function(p) { return custom(a, p); };
29
30 return elasticOut;
31})(amplitude, period);
32
33export var elasticInOut = (function custom(a, p) {
34 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
35
36 function elasticInOut(t) {
37 return ((t = t * 2 - 1) < 0
38 ? a * tpmt(-t) * Math.sin((s - t) / p)
39 : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
40 }
41
42 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
43 elasticInOut.period = function(p) { return custom(a, p); };
44
45 return elasticInOut;
46})(amplitude, period);
Note: See TracBrowser for help on using the repository browser.