-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasing.html
More file actions
75 lines (58 loc) · 1.8 KB
/
easing.html
File metadata and controls
75 lines (58 loc) · 1.8 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Simple Canvas Example</title>
<style>
canvas {
border: 3px #CCC solid;
}
</style>
</head>
<body>
<div id="container">
<canvas id="myCanvas" height="450" width="450"></canvas>
</div>
<script src="http://kirupa.googlecode.com/svn/trunk/easing.js"></script>
<script>
var mainCanvas = document.getElementById("myCanvas");
var mainContext = mainCanvas.getContext('2d');
var canvasWidth = mainCanvas.width;
var canvasHeight = mainCanvas.height;
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
var iteration = 0;
var totalIterations = 200;
var easingValue;
var moveRight = true;
function drawCircle() {
mainContext.clearRect(0, 0, canvasWidth, canvasHeight);
// color in the background
mainContext.fillStyle = "#EEEEEE";
mainContext.fillRect(0, 0, canvasWidth, canvasHeight);
// draw the circle
mainContext.beginPath();
var radius = 100;
if (moveRight) {
easingValue = easeInOutExpo(iteration, -100, 650, totalIterations);
} else {
easingValue = easeInExpo(iteration, 650, -750, totalIterations);
}
mainContext.arc(easingValue, 225, radius, 0, Math.PI * 2, false);
mainContext.closePath();
// color in the circle
mainContext.fillStyle = "#006699";
mainContext.fill();
if (iteration < totalIterations) {
iteration++;
} else {
iteration = 0;
moveRight = !moveRight;
}
requestAnimationFrame(drawCircle);
}
drawCircle();
</script>
</body>
</html>