-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
77 lines (67 loc) · 2.46 KB
/
index.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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/canvas.js"></script>
<script type="text/javascript" src="js/keys.js"></script>
<script type="text/javascript">
var canvas,
demo,
_key,
_mouse = {x: 0, y: 0},
_cursor = {x: 0, y: 0};
var rect, rect2, rect3;
function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function init(){
_key = new Key();
canvas = document.getElementById("demo");
demo = new Canvas(canvas);
canvas.addEventListener('mousemove', function(e){
_mouse.x = e.clientX + window.scrollX;
_mouse.y = e.clientY + window.scrollY;
}, false);
canvas.addEventListener('click', function(e){
demo.animate.togglePlay();
});
rect = new demo.draw.Rectangle(
300, 300, // Position
70, 30, // Size
"#F00" // Color
).align("center");
rect.speed = 5; // Movement speed / pixels per frame
rect.rspeed = 3; // Rotation speed / degrees per frame
var draw = function(delta){
if( _key.down ){
if( _key.is("left") ){ // Arrow left // 37
rect.rotate(rect.rspeed*-1);
}
if( _key.is("right") ){ // Arrow right // 39
rect.rotate(rect.rspeed);
}
if( _key.is("up") || _key.is("down") ){
var dirAngle = rect.rotation / 180*Math.PI;
var x = rect.speed * ( _key.is("down") ? -1 : 1 ) * Math.cos(dirAngle);
var y = rect.speed * ( _key.is("down") ? -1 : 1 ) * Math.sin(dirAngle);
rect.move(x, y);
}
}
};
demo.animate.addDraw(draw);
demo.animate.play();
}
</script>
<style type="text/css">
html, body{min-height: 100%; height: 100%; margin: 0; padding: 0;}
canvas{border: 1px solid #CCC;}
</style>
</head>
<body>
<canvas id="demo" width="800" height="700">
Update your browser.
</canvas>
<script type="text/javascript">init();</script>
</body>
</html>