-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoiseGenerator.py
More file actions
47 lines (34 loc) · 955 Bytes
/
noiseGenerator.py
File metadata and controls
47 lines (34 loc) · 955 Bytes
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
"""
This function makes `noiseLen` number of vector3 and
write them all into the NoiseTable.h file
"""
import random
noiseLen = 1000
values = []
for _ in range(noiseLen):
values.append([
random.gauss(0, 1),
random.gauss(0, 1),
random.gauss(0, 1)
])
avg_x = sum(v[0] for v in values) / noiseLen
avg_y = sum(v[1] for v in values) / noiseLen
avg_z = sum(v[2] for v in values) / noiseLen
for v in values:
v[0] -= avg_x
v[1] -= avg_y
v[2] -= avg_z
def value(i):
return f"{values[i][0]:.3f}, {values[i][1]:.3f}, {values[i][2]:.3f}"
out = """#ifndef NOISE_TABLE_H
#define NOISE_TABLE_H
#include "vector3.h"
inline const Vector3 brownianNoise[""" + str(noiseLen) + """] = {\n\t""" + ",\n\t".join([
f"Vector3({value(i)})" for i in range(noiseLen)
]) + """
};
constexpr int brownianNoiseSize = """ + str(noiseLen) + """;
#endif
"""
with open("include/NoiseTable.h", "w") as file:
file.write(out)