-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathTriangleWave.java
More file actions
38 lines (32 loc) · 1.25 KB
/
TriangleWave.java
File metadata and controls
38 lines (32 loc) · 1.25 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
package nodebox.util.waves;
public class TriangleWave extends AbstractWave {
public TriangleWave(float period, float amplitude) {
super(period, 0f, amplitude);
}
public TriangleWave(float period, float phase, float amplitude) {
super(period, phase, amplitude);
}
public TriangleWave(float period, float phase, float amplitude, float offset) {
super(period, phase, amplitude, offset);
}
/**
* Creates a suitable TriangleWave object from other than the constructor arguments.
* The wave oscillates between min and max values
*
* @param min the minimum value
* @param max the maximum value
* @param period the length (expressed in time) over which the wave makes a full triangular movement
* @return a new TriangleWave
*/
public static TriangleWave from(float min, float max, float period) {
float amplitude = (max - min) / 2;
float offset = min + amplitude;
return new TriangleWave(period, 0f, amplitude, offset);
}
protected float computeValue(float phase) {
return Math.abs((phase / TWO_PI) * 2 - 1) * amplitude * 2 - amplitude;
}
protected float adjustedTime(float t) {
return t + getPeriod() / 4;
}
}