-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
108 lines (87 loc) · 3.71 KB
/
main.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include "include/noise_graph_generator.h"
using namespace std;
void runTests() {
GrayImage* img;
int width, height;
int seed = (int)time(0);
width = height = 512;
// 白噪声,1x1
cout << "生成 1x1 白噪声(White Noise) 图像...";
img = &whiteNoise(width, height, 1, seed);
savePPMP2(*img, "white_noise_1x1.ppm");
savePPMP2(img->spectrum(), "white_noise_1x1_spectrum.ppm");
cout << "\r生成 1x1 白噪声(White Noise) 图像完成" << endl;
// 白噪声,16x16
cout << "生成 16x16 白噪声(White Noise) 图像...";
img = &whiteNoise(width, height, 16, seed);
savePPMP2(*img, "white_noise_16x16.ppm");
savePPMP2(img->spectrum(), "white_noise_16x16_spectrum.ppm");
cout << "\r生成 16x16 白噪声(White Noise) 图像完成" << endl;
// 连续噪声,16x16
cout << "生成 16x16 值噪声(Value Noise) 图像...";
img = &valueNoise(width, height, 16, seed);
savePPMP2(*img, "value_noise_16x16.ppm");
savePPMP2(img->spectrum(), "value_noise_16x16_spectrum.ppm");
cout << "\r生成 16x16 值噪声(Value Noise) 图像完成" << endl;
// 柏林噪声,16x16
cout << "生成 16x16 柏林噪声(Perlin Noise) 图像...";
img = &perlinNoise(width, height, 16, seed);
savePPMP2(*img, "perlin_noise_16x16.ppm");
savePPMP2(img->spectrum(), "perlin_noise_16x16_spectrum.ppm");
cout << "\r生成 16x16 柏林噪声(Perlin Noise) 图像完成" << endl;
// 柏林噪声,16x16+量化
cout << "生成 64x64 柏林噪声(Perlin Noise)+量化 图像...";
img = &perlinNoise(width, height, 64, seed);
img->quantify(10);
savePPMP2(*img, "perlin_noise_64x64_quantify_10.ppm");
savePPMP2(img->spectrum(), "perlin_noise_64x64_spectrum.ppm");
cout << "\r生成 64x64 柏林噪声(Perlin Noise)+量化 图像完成" << endl;
// 值噪声,分形
cout << "生成 分形+值噪声 图像...";
img = new GrayImage(width, height);
int startCellSize = 64;
int octave = 5;
float tempScale = 0.5;
while (startCellSize > 0 && octave > 0) {
GrayImage* t = &valueNoise(width, height, startCellSize, seed);
t->mul(tempScale);
img->add(*t);
tempScale /= 2;
startCellSize /= 2;
octave--;
}
savePPMP2(*img, "fabric_value_noise.ppm");
savePPMP2(img->spectrum(), "fabric_value_noise_spectrum.ppm");
cout << "\r生成 分形+值噪声 图像完成" << endl;
// 柏林噪声,分形
cout << "生成 分形+柏林噪声 图像...";
img = new GrayImage(width, height);
startCellSize = 64;
octave = 5;
tempScale = 0.5;
while (startCellSize > 0 && octave > 0) {
GrayImage* t = &perlinNoise(width, height, startCellSize, seed);
t->mul(tempScale);
img->add(*t);
tempScale /= 2;
startCellSize /= 2;
octave--;
}
savePPMP2(*img, "fabric_perlin_noise.ppm");
savePPMP2(img->spectrum(), "fabric_perlin_noise_spectrum.ppm");
cout << "\r生成 分形+柏林噪声 图像完成" << endl;
cout << "生成 16x16 单形噪声(Simplex Noise) 图像...";
img = &simplexNoise(width, height, 16, seed);
savePPMP2(*img, "simplex_noise_16x16.ppm");
savePPMP2(img->spectrum(), "simplex_noise_16x16_spectrum.ppm");
cout << "\r生成 16x16 单形噪声(Simplex Noise) 图像完成" << endl;
cout << "生成 16x16 沃利噪声(Worley Noise) 图像...";
img = &worleyNoise(width, height, 16, seed);
savePPMP2(*img, "worley_noise_16x16.ppm");
savePPMP2(img->spectrum(), "worley_noise_16x16_spectrum.ppm");
cout << "\r生成 16x16 沃利噪声(Worley Noise) 图像完成" << endl;
}
int main() {
runTests();
}