-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.js
85 lines (82 loc) · 1.84 KB
/
particle.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Particle {
constructor(x,y,w,minMax){
this.x = x;
this.y = y;
this.w = w;
this.minMax = minMax;
this.step = 0;
this.inPlace = false;
}
move(){
this.x -= 1;
this.y += random(-this.minMax, this.minMax);
if(this.y < 0){
this.y = 0;
}
for(var j = 0; j < p.length; j += 1){
if(p[j] == this){
continue;
}
var dx = p[j].x - this.x;
var dy = p[j].y - this.y;
var radii = (this.w/2) + (p[j].w/2);
if ( ( dx * dx ) + ( dy * dy ) < radii * radii )
{
if(this.step == 0){
isDone = true;
break;
} else {
addParticle();
break;
}
}
}
if(this.x <= 0){
addParticle();
}
this.step += 1;
}
snapMove(){
while(this.inPlace == false){
this.x -= 1;
this.y += random(-this.minMax, this.minMax);
if(this.y < 0){
this.y = 0;
}
for(var j = 0; j < p.length; j += 1){
if(p[j] == this){
continue;
}
var dx = p[j].x - this.x;
var dy = p[j].y - this.y;
var radii = (this.w/2) + (p[j].w/2);
if ((dx * dx) + (dy * dy) < radii * radii)
{
if(this.step == 0){
isDone = true;
this.inPlace = true;
break;
} else {
addParticle();
this.inPlace = true;
return;
}
}
}
if(this.x <= 0){
addParticle();
this.inPlace = true;
}
this.step += 1;
}
}
show(){
for(var v = 0; v < 8; v += 1){
rotate((PI/4) * v)
stroke(255);
ellipse(this.x, this.y, this.w, this.w);
stroke(255);
ellipse(this.x, -this.y, this.w, this.w);
}
}
}