-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (36 loc) · 1.11 KB
/
main.cpp
File metadata and controls
49 lines (36 loc) · 1.11 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
#include <string>
#include <array>
#include <map>
#include <ostream>
#include "noise.h"
#include "colors.h"
#define SIZE 400
int main() {
std::ofstream img("test.pbm");
img << "P3" << std::endl;
img << SIZE << " " << SIZE << std::endl;
img << "255" << std::endl;
// Noise generation
NoiseGenerator ng(time(NULL), 8, 4, 4, 0.5);
ng.setScaling(1, 1);
std::array<std::array<double, SIZE>, SIZE> arr = {};
for (int y = 0; y < SIZE; ++y) {
for (int x = 0; x < SIZE; ++x) {
double dx = x / static_cast<double>(SIZE);
double dy = y / static_cast<double>(SIZE);
arr[x][y] = ng.noise(dx, dy, 0.0);
}
}
// Color
ColorMap colors("resources/colormap.txt");
for (int y = 0; y < SIZE; ++y) {
for (int x = 0; x < SIZE; ++x) {
int height = round(arr[x][y] * (colors.size() - 1));
Color color = colors.getColorStruct(height);
img << (int)color.r << " " << (int)color.g << " " << (int)color.b << " " << std::endl;
}
img << std::endl;
}
img.close();
return 0;
}