/
MathUtil.pde
68 lines (56 loc) · 1.38 KB
/
MathUtil.pde
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
class MathUtil {
// utils
float flSin(float n) {
return (float) Math.sin(n);
}
float flCos(float n) {
return (float) Math.cos(n);
}
float flSq(float n) {
return (float) Math.pow(n, 2);
}
float flCu(float n) {
return (float) Math.pow(n, 3);
}
void calcVecMax(PVector store, PVector pt) {
store.x = Math.max(store.x, pt.x);
store.y = Math.max(store.y, pt.y);
store.z = Math.max(store.z, pt.z);
}
void calcVecMin(PVector store, PVector pt) {
store.x = Math.min(store.x, pt.x);
store.y = Math.min(store.y, pt.y);
store.z = Math.min(store.z, pt.z);
}
float roundTo(float n, int places) {
return round(n * pow(10, places)) / pow(10, places);
}
float noiseIndex = random(20);
float noiseRandom(float min, float max) {
noiseIndex += 0.1;
return min + (noise(noiseIndex) * (max - min));
}
}
class NoiseVector {
float inc = 0.01;
float[][] ranges;
float[] indexes;
NoiseVector(float[][] cRanges) {
ranges = cRanges;
indexes = new float[ranges.length];
for (int i = 0, len = ranges.length; i < len; ++i) {
indexes[i] = random(20);
}
}
float[] getNext() {
float[] values = new float[ranges.length];
for (int i = 0, len = ranges.length; i < len; ++i) {
indexes[i] += inc;
values[i] = valFromRng(indexes[i], ranges[i]);
}
return values;
}
float valFromRng(float ind, float[] rng) {
return rng[0] + noise(ind) * (rng[1] - rng[0]);
}
}