forked from jeslie0/julia-mandel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjulia.c
More file actions
102 lines (92 loc) · 2.39 KB
/
julia.c
File metadata and controls
102 lines (92 loc) · 2.39 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
102
#include <stdio.h>
#include <complex.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <png.h>
#define size 2000
#define max_iteration 40
int image[size][size];
double _Complex c;
double _Complex z;
int i;
int j;
int colour;
int iteration;
int row;
int col;
int main(int argc, char *argv[]) {
int test;
srand(time(NULL));
test = rand() % 6;
for(row=0; row<size; row++) {
for(col=0; col<size; col++) {
c = atof(argv[1])+atof(argv[2])*I;
z = (((float)col - (float)size/2)*4/size) + (((float)row - (float)size/2)*4/size)*I;
iteration = 0;
while(sqrt(creal(z)*creal(z) + cimag(z)*cimag(z)) < 2 && (iteration < max_iteration)) {
z = z*z + c;
iteration++;
}
if(iteration == max_iteration) {
colour = 255;
} else {
colour = iteration*10%255;
}
image[row][col] = colour;
}
}
FILE *f = fopen("/home/pi/Programming/Twitter/julia.ppm", "wb");
fprintf(f, "P6\n%i %i 255\n", size, size);
if (test == 0) {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(image[i][j],f);
fputc(0,f);
fputc(0,f);
}
}
} else if (test == 1) {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(0,f);
fputc(image[i][j],f);
fputc(0,f);
}
}
} else if (test == 2) {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(0,f);
fputc(0,f);
fputc(image[i][j],f);
}
}
} else if (test == 3) {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(image[i][j],f);
fputc(image[i][j],f);
fputc(0,f);
}
}
} else if (test == 3) {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(image[i][j],f);
fputc(0,f);
fputc(image[i][j],f);
}
}
} else {
for(i=0; i<size; i++) {
for(j=0; j<size; j++) {
fputc(0,f);
fputc(image[i][j],f);
fputc(image[i][j],f);
}
}
};
fclose(f);
return 0;
}