-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre_frame.js
53 lines (40 loc) · 1.5 KB
/
re_frame.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
var ReFrame = function(particles, Draw, Compare, Metrics, boost, speedboost, bubble)//call this every frame in the `refresh` function
{
for ( var i = 0; i < particles.length; i++ )
{
Draw(particles[i])
Metrics(particles[i])
particles[i][0] += boost * particles[i][2]
particles[i][1] += boost * particles[i][3]
particles[i][2] += 2 * speedboost * (Math.random() - 0.5)
particles[i][3] += 2 * speedboost * (Math.random() - 0.5)
for ( var j = 0; j < particles.length; j++ )
{
if ( i != j )
{
if ( Math.sqrt(Math.pow(particles[i][0]-particles[j][0], 2)+Math.pow(particles[i][1]-particles[j][1], 2)) <= bubble )
{
particles[i][2] = -particles[i][2]
particles[i][3] = -particles[i][3]
}
}
Compare(particles[i], particles[j])
}
if ( particles[i][0] < 0 ){
particles[i][0] = 0
particles[i][2] = -particles[i][2]
}
if ( particles[i][0] > 1 ){
particles[i][0] = 1
particles[i][2] = -particles[i][2]
}
if ( particles[i][1] < 0 ){
particles[i][1] = 0
particles[i][3] = -particles[i][3]
}
if ( particles[i][1] > 1 ){
particles[i][1] = 1
particles[i][3] = -particles[i][3]
}
}
}