-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrow.html
47 lines (43 loc) · 1020 Bytes
/
arrow.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Ball</title>
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<script src="./js/utils.js"></script>
<script src="./js/arrow.js"></script>
<script>
window.onload = function(){
var canvas = document.getElementById("canvas"),
context = canvas.getContext('2d'),
mouse = utils.captureMouse(canvas),
arrow = new Arrow(),
//speed = 3;
vr = 1,
vx = 0,
vy = 0,
force = 0.05;
arrow.x = canvas.width / 2;
arrow.y = canvas.height / 2;
(function drawFrame(){
window.requestAnimationFrame(drawFrame, canvas);
context.clearRect(0, 0, canvas.width, canvas.height);
var dx = mouse.x - arrow.x,
dy = mouse.y - arrow.y,
angle = Math.atan2(dy, dx), //radians(弧度)
ax = Math.cos(angle) * force,
ay = Math.sin(angle) * force;
arrow.rotation = angle;
vx += ax;
vy += ay;
arrow.x += vx;
arrow.y += vy;
arrow.draw(context);
})();
}
</script>
</body>
</html>