-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjulia.cpp
More file actions
101 lines (78 loc) · 2.58 KB
/
julia.cpp
File metadata and controls
101 lines (78 loc) · 2.58 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
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
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <array>
#include <vector>
#include <complex>
#include <cstdint>
#include <omp.h>
//M: width, N: height
#define xMin -1.3
#define xMax 1.3
#define yMin -1.3
#define yMax 1.3
#define ITER 200
#define M 4000
#define PIX_RANGE 255
#define N int((double(yMax-yMin)/(xMax-xMin))*M)
using namespace std;
void writePMG(vector<vector<vector<uint16_t>>>& set){
ofstream imageFile;
imageFile.open ("example.pgm");
imageFile << "P3\n";
imageFile << M << " " << N << "\n";
imageFile << PIX_RANGE << "\n";
for(auto& i:set){
for(auto& j:i){
for(auto& z:j){
imageFile << z << " ";
}
imageFile << " ";
}
imageFile << "\n";
}
imageFile.close();
}
//takes in x and y pixel cooridnate, outputs equation mappings
void map(int x, int y, double* outX, double* outY){
*outX = (double(x)/M)*(xMax-xMin)+double(xMin);
*outY= (double(y)/N)*(yMax-yMin)+double(yMin);
}
int main() {
vector<vector<vector<uint16_t>>> set(N,vector<vector<uint16_t>>(M,vector<uint16_t>(3)));
cout << M << " X " << N << endl;
//pow(0.65-0.4198i,1), pow(z,4);
//pow(0.3755-0.3i,1)
complex<double> c = pow(-0.071-0.665i,0.999);
#pragma omp parallel for
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
double x, y;
map(j,i,&x,&y);
set[i][j][0] = 255;
set[i][j][1] = 100;
set[i][j][2] = 0;
complex<double> z(x,y);
for(int it = 0; it < ITER; it++){
z = pow(z,2) + c;
//if escaped to infinity very quickly, we set the pixel to a fixed color
if(real(z*conj(z))>(xMin*xMin) && it < 6){
set[i][j][0] = 0;
set[i][j][1] = 0;
set[i][j][2] = 0;
break;
}
//otherwise, we color it accoridng to iteration count
if(real(z*conj(z))>(xMin*xMin)){
set[i][j][0] = 200;
set[i][j][1] = 0;
set[i][j][2] = sin(int((double(it)/ITER)*PIX_RANGE/4))*PIX_RANGE/30;
break;
}
}
}
}
writePMG(set);
return 0;
}