-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandelb_c.c
More file actions
49 lines (38 loc) · 1.15 KB
/
mandelb_c.c
File metadata and controls
49 lines (38 loc) · 1.15 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
#include <stdio.h>
#include <stdlib.h>
#define WIDTH 80
#define HEIGHT 24
int mandelbrot(double real, double imag, int max_iter) {
int iter = 0;
double real_temp, imag_temp, real_squared, imag_squared;
while (iter < max_iter && (real_squared + imag_squared) < 4.0) {
real_temp = real_squared - imag_squared + real;
imag_temp = 2 * real * imag + imag;
real = real_temp;
imag = imag_temp;
real_squared = real * real;
imag_squared = imag * imag;
iter++;
}
return iter;
}
void displayMandelbrot() {
int max_iter = 1000;
for (int row = 0; row < HEIGHT; row++) {
for (int col = 0; col < WIDTH; col++) {
double real = (col - WIDTH / 2.0) * 4.0 / WIDTH;
double imag = (row - HEIGHT / 2.0) * 4.0 / HEIGHT;
int value = mandelbrot(real, imag, max_iter);
if (value == max_iter) {
putchar('#'); // Point is in the Mandelbrot set
} else {
putchar(' '); // Point is not in the Mandelbrot set
}
}
putchar('\n');
}
}
int main() {
displayMandelbrot();
return 0;
}