forked from tweenjs/tween.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_graphs_custom_functions.html
101 lines (76 loc) · 2.83 KB
/
12_graphs_custom_functions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tween.js / graphs for custom easing functions</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body {
margin: 0px;
}
#target {
font-size: 13px;
padding: 0px 32px;
}
</style>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="info" style="position: relative;">
<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
<h2>12 _ graphs for custom easing functions</h2>
<p>A version of the <a href="03_graphs.html">graphs</a> example, but using custom easing functions (not included in <a href="https://github.com/tween.js/tween.js">tween.js</a> by default).</p>
</div>
<div id="target"></div>
<script src="../src/Tween.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script src="js/createGraph.js"></script>
<script>
window.addEventListener('load', function() {
init();
animate();
});
function init() {
var target = document.getElementById('target');
target.appendChild( createGraph( 'Ten Steps', tenStepsEasing ) );
target.appendChild( document.createElement( 'br' ) );
for(var i = 0; i < 4; i++) {
var numSteps = (i + 1) * 4;
target.appendChild( createGraph(numSteps + ' steps', createStepFunction(numSteps)) );
}
target.appendChild( document.createElement( 'br' ) );
target.appendChild( createGraph('Random', randomEasing) );
target.appendChild( document.createElement( 'br' ) );
target.appendChild( createGraph('Noisy Exponential.InOut', createNoisyEasing(0.1, TWEEN.Easing.Exponential.InOut) ) );
target.appendChild( createGraph('Noisy Elastic.InOut', createNoisyEasing(0.1, TWEEN.Easing.Elastic.InOut) ) );
target.appendChild( createGraph('Noisy Circular.InOut', createNoisyEasing(0.1, TWEEN.Easing.Circular.InOut) ) );
}
function animate() {
requestAnimationFrame( animate );
TWEEN.update();
}
function tenStepsEasing(k) {
return (Math.floor(k * 10) / 10);
}
// This is where we get very meta and write a function for
// generating functions! The returned function is similar to
// the tenStepsEasing function above, but the number of steps
// is passed as a parameter
function createStepFunction(numSteps) {
return function(k) {
return (Math.floor(k * numSteps) / numSteps);
}
}
function randomEasing(k) {
return Math.random();
}
// Getting meta again: why not use existing functions as the
// base for new easing functions?
function createNoisyEasing(randomProportion, easingFunction) {
var normalProportion = 1.0 - randomProportion;
return function(k) {
return randomProportion * Math.random() + normalProportion * easingFunction(k);
}
}
</script>
</body>
</html>