-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
88 lines (71 loc) · 1.97 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<style>
html, body {
margin: 0;
background: #333;
overflow: hidden;
width: 100%;
height: 100%;
color: #222;
}
#circle {
position: absolute;
left: 0; top : 0;
padding: 10px;
width: 50px;
height: 50px;
background: #fff;
border-radius: 50px;
}
</style>
<title>Path.js Test</title>
</head>
<body>
<div id="circle"></div>
<script src="./Path.js"></script>
<script>
var data = [];
var x, y, z, t;
for (var i = 0; i < 1000; i++) {
x = Math.round( Math.random() * 400 );
y = Math.round( Math.random() * 400 );
z = Math.round( Math.random() * 100 );
t = i * 20;
// console.log("x: ", x, "y: ", y, "z: ", z, "t: ", t);
data.push( new Point(x, y, z, t) );
}
var timer = Date.now();
var path = new Path(data);
console.log("To create a path with", data.length, "points it takes", (Date.now() - timer), "ms.");
// console.log("t = 200.1", path.getXYZ(200.1) );
// console.log("t = 1013.1", path.getXYZ(1013.1) );
window.requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
var time = 0, inc = 4;
var d = document.getElementById("circle");
function step (timestamp) {
var point = path.getXYZ(time);
// console.log("t: ", time, point);
if (point.x == 0 && point.y == 0 && point.z == 0) {
console.log("error @ time = ", time, point);
return;
}
d.style.left = point.x + "px";
d.style.top = point.y + "px";
d.style.width = point.z + "px";
d.style.height = point.z + "px";
time += inc;
if (time < path.maxTime) {
requestAnimationFrame(step);
}
}
requestAnimationFrame(step);
</script>
</body>
</html>