forked from Mercer01/hackTheGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticle.js
More file actions
46 lines (41 loc) · 1.19 KB
/
particle.js
File metadata and controls
46 lines (41 loc) · 1.19 KB
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
"use strict";
class Particle {
constructor(x, y) {
this.x = x + (Math.random() - 0.5) * 100;
this.y = y + (Math.random() - 0.5) * 100;
this.vx = (Math.random() - 0.5) * 100;
this.vy = (Math.random() - 0.5) * 64;
const size = (100 - (this.vx + this.vy) / 2) / 5;
//const rotation = (Math.random() * 90) * Math.PI / 180;
this.vertices = []
this.vertices.push({
x: 0,
y: 0
});
this.vertices.push({
x: size,
y: 0
});
this.vertices.push({
x: size,
y: size
});
this.vertices.push({
x: 0,
y: size
});
}
draw() {
this.x += this.vx;
this.y += this.vy;
this.vy += 1;
context.beginPath();
context.moveTo(this.vertices[0].x + this.x, this.vertices[0].y + this.y);
for (let i = 1; i < this.vertices.length; i++) {
context.lineTo(this.vertices[i].x + this.x, this.vertices[i].y + this.y)
}
context.lineTo(this.vertices[0].x + this.x, this.vertices[0].y + this.y);
context.fill();
context.stroke();
}
}