-
Notifications
You must be signed in to change notification settings - Fork 0
/
pclt.cpp
74 lines (60 loc) · 2.38 KB
/
pclt.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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
void writePPMImage(int* data, int width, int height, const char *filename, int maxIterations)
{
FILE *fp = fopen(filename, "wb");
// write ppm header
fprintf(fp, "P6\n");
fprintf(fp, "%d %d\n", width, height);
fprintf(fp, "255\n");
for (int i = 0; i < width*height; ++i) {
float mapped = pow( std::min(static_cast<float>(maxIterations), static_cast<float>(data[i])) / 256.f, .5f);
unsigned char result = static_cast<unsigned char>(255.f * mapped);
for (int j = 0; j < 3; ++j)
fputc(result, fp);
}
fclose(fp);
printf("Wrote image file %s\n", filename);
}
int main() {
//size of image generated
int width = 1450;
int height = 1000;
//probability of elements
int a[] = {1, 2, 3, 4, 5, 6};
// There is an extreme situation
// int a[] = {
// 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //#'1' = 40
// 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //#'1' = 40
// 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //#'1' = 40
// 2,3,4,5,6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //#'1' = 15
// };
int count = sizeof(a)/sizeof(int);
int* sumArr = new int[width];
int* output = new int[width*height];
//height*30 is the number of samples, there is 1000*30= 30000
for (int i=0; i<height*30; i++) {
int temp = a[random()%count];
//how many times added
for (int j=0; j<100; j++) {
temp = temp + a[random()%count];
}
sumArr[temp] = sumArr[temp]+1;
}
for (int i=0; i<width; i++) {
// sumArr[i]/2 to scale image
for (int j=height-1; j>=height-sumArr[i]; j--) {
//widening images
for (int k=0; k<10; k++) {
output[j*width+i*10+k]=256;
}
}
}
writePPMImage(output, width, height, "output-image.ppm", 256);
delete[] sumArr;
delete[] output;
return 0;
}