This repository was archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImpulse.pde
More file actions
91 lines (80 loc) · 2.52 KB
/
Impulse.pde
File metadata and controls
91 lines (80 loc) · 2.52 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
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
86
87
88
89
90
91
ArrayList<Impulse> impulses = new ArrayList<Impulse>();
void addNewImpulse(PVector pos, float intens, int frequence) {
impulses.add(new Impulse(pos, intens, frequence));
}
float cumulatedImpulseIntensityAtPosition(PVector point) {
float cumulatedIntensity = 0;
for (int i=0; i < impulses.size(); i++) {
Impulse impulse = impulses.get(i);
cumulatedIntensity += impulse.intensityAtPosition(point);
}
return cumulatedIntensity;
}
float cumulatedImpulseFrequenceAtPosition(PVector point) {
float cumulatedFrequence = 0;
float cumulatedIntensity = 0;
int numberOfWavesAtPoint = 0;
for (int i=0; i < impulses.size(); i++) {
Impulse impulse = impulses.get(i);
if (impulse.intensityAtPosition(point) > 0)
{
cumulatedIntensity += impulse.intensityAtPosition(point);
cumulatedFrequence += (impulse.intensityAtPosition(point) * impulse.frequenceIndex);
numberOfWavesAtPoint ++;
}
}
return cumulatedFrequence / cumulatedIntensity / numberOfWavesAtPoint;
}
void updateImpulses() {
for (int i = 0; i < impulses.size(); i++) {
Impulse impulse = impulses.get(i);
impulse.travelWave();
if (impulse.delete) {
impulses.remove(i);
i--;
}
}
}
class Impulse {
float speed = 0.25; // m/s
PVector origin = new PVector(0, 0, 0);
float originalIntensity = 1.0;
float actualIntensity = 1.0;
float radius = .0;
float maxRadius = 50.0;
float waveLength = 30.0; // meters
float lengthWithMaxIntensity = 8.0;
float halfWaveLength = 2.0;
boolean delete = false;
int lastTime = 0;
int frequenceIndex = 0;
Impulse(PVector position, float _originalIntensity, int _frequence) {
radius = 1.0;
origin = position;
frequenceIndex = _frequence;
originalIntensity = _originalIntensity;
halfWaveLength = waveLength * 0.5;
lastTime = millis();
}
void travelWave() {
if (radius <= maxRadius) {
radius += (millis() - lastTime) * 0.001 * speed;
} else {
delete = true;
}
actualIntensity = originalIntensity;
}
float intensityAtPosition(PVector position) {
float intensity = 0.0;
float distance = abs(PVector.dist(position, origin));
if (distance > (radius - waveLength) && distance < radius) {
if (radius - distance < lengthWithMaxIntensity) {
intensity = map(radius - distance, .0, lengthWithMaxIntensity, actualIntensity, 0.7);
} else {
intensity = map(radius - distance, lengthWithMaxIntensity, waveLength, 0.7, 0.0);
}
return intensity;
}
return .0;
}
}