-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.html
84 lines (76 loc) · 2.2 KB
/
ball.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>ball</title>
<meta name="description" content="" />
<meta name="author" content="PRO11_6" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<style type="text/css">
* { margin: 0; padding: 0;}
body {
overflow: hidden;
}
canvas {
/*border: 1px solid red;*/
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="src/kinetic.latest.js"></script>
<script type="text/javascript">
function Ball(stage, layer) {
// Stage initialization
var sW = stage.getWidth();
var sH = stage.getHeight();
var centerX = sW / 2;
var centerY = sH / 2;
// Ball initialization
var radius = 25;
var ball = new Kinetic.Circle({
radius: 25,
x: 0,
y: centerY,
fill: '#f50'
});
// Layer animation
var amplitude = 150;
var period = 1500;
var oldX = 1;
var anim = new Kinetic.Animation({
func: function(frame) {
var pos = ball.attrs.x + (mouseX - ball.attrs.x) * 0.1;
var posY = Math.sin(pos * Math.PI * 4 / sW) * 150 + sH / 2;
ball.setX(Math.cos(frame.time / 1500 * Math.PI / 2) * 150 + sW / 2);
ball.setY(-Math.sin(frame.time / 1500 * Math.PI * 2) * 150 + sH / 2);
//ball.setY(posY);
},
node: layer
});
var mouseX = 0;
window.onmousemove = function(e) {
mouseX = e.pageX;
}
anim.start();
layer.add(ball);
stage.add(layer);
};
window.onload = function() {
var stage = new Kinetic.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});
var layer = new Kinetic.Layer();
Ball(stage, layer);
}
</script>
</body>
</html>