-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.js
67 lines (58 loc) · 1.02 KB
/
point.js
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
/**
@ author :ormuseldesu
@ date :2019/09/06 (September 6)
@ description :my custom point class to spawn particles
*/
class Point
{
constructor(x, y, radius)
{
this.vector = new Vector(x, y);
this.velocity = new Vector();
this.colour = this.getRandomColour();
this.r = radius;
}
draw()
{
context.beginPath();
context.arc(
this.vector.getX(),
this.vector.getY(),
this.r, 0, Math.PI * 2
);
context.fillStyle = this.colour;
context.fill();
context.closePath();
}
update()
{
this.vector.add (this.velocity);
}
setVelocity(vector)
{
this.velocity = vector;
}
getVelocity()
{
return this.velocity;
}
getRandomColour()
{
let red = Math.random() * 255;
let green = Math.random() * 255;
let blue = Math.random() * 255;
return `rgb(${red},${green},${blue})`;
}
getX()
{
return this.vector.getX();
}
getY()
{
return this.vector.getY();
}
getRadius()
{
return this.r;
}
}