-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep0.html
81 lines (75 loc) · 2.06 KB
/
step0.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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Multiblaster</title>
<style>
html, body {
margin: 0;
height: 100%;
background: #999;
}
#canvas {
object-fit: contain;
max-width: 100%;
max-height: 100%;
background: #000;
}
</style>
</head>
<body>
<canvas id="canvas" width="1000" height="1000"></canvas>
<script>
// create a drawing context
const context = canvas.getContext("2d");
context.lineWidth = 3;
context.strokeStyle = "white";
// define a moving Asteroid
class Asteroid {
constructor() {
this.x = Math.random() * 1000,
this.y = Math.random() * 1000,
this.dx = Math.random() * 4 - 2,
this.dy = Math.random() * 4 - 2,
this.a = 0;
this.da = 0.02;
this.move();
}
move() {
this.x = (this.x + this.dx + 1000) % 1000;
this.y = (this.y + this.dy + 1000) % 1000;
this.a = (this.a + this.da + Math.PI) % Math.PI;
setTimeout(() => this.move(), 50);
}
};
// create some asteroids
const asteroids = new Set();
asteroids.add(new Asteroid());
asteroids.add(new Asteroid());
asteroids.add(new Asteroid());
// draw asteroids in each render frame
function update() {
context.clearRect(0, 0, 1000, 1000);
context.lineWidth = 3;
context.strokeStyle = "white";
for (const asteroid of asteroids) {
const {x, y, a} = asteroid;
context.save();
context.translate(x, y);
context.rotate(a);
context.beginPath();
context.moveTo(+40, 0);
context.lineTo( 0, +40);
context.lineTo(-40, 0);
context.lineTo( 0, -40);
context.closePath();
context.stroke();
context.restore();
}
requestAnimationFrame(update);
}
// start drawing loop
update();
</script>
</body>
</html>