forked from atoneyda/username
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled-5.html
68 lines (60 loc) · 1.57 KB
/
Untitled-5.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
<!DOCTYPE html>
<html>
<head>
<title> insert title here lol </title>
<style>
li {color: pink;}
</style>
</head>
<body>
<canvas id="myCanvas" width="800" height= "800"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var x = 0
var y = 0
var vx = 10
var vy = 10
document.addEventListener( 'keydown', function(event) {
console.log(event)
if (event.key == "ArrowLeft") {
vx = -vx
} else if (event.key == "ArrowUp") {
vy = -vy
}
if (event.key == "ArrowRight") {
vx = -vx
} else if (event.key == "ArrowDown") {
vy = -vy
}
})
function ball() {
ctx.clearRect(0,0, c.width, c.height)
x = x + vx;
y = y + vy;
if (x > c.width || x < 0) {
vx = -vx
}
if (y > c.height || y < 0) {
vy = -vy
}
ctx.beginPath();
ctx.arc(x,y,40,0,2*Math.PI);
ctx.stroke();
requestAnimationFrame(ball);
ctx.rect(20,20,500,100);
ctx.stroke();
ctx.clearRect(20,20,500, 100)
x = x + vx;
y = y + vy;
if (x > c.width || x < 500) {
vx = -vx
}
if (y > c.height || y < 100) {
vy = -vy
}
}
ball()
</script>
</body>
</html>