feat(c): working mandelbrot

This commit is contained in:
2026-07-18 00:57:20 +02:00
parent 635119e27a
commit 38589ceca6
+13 -9
View File
@@ -7,10 +7,10 @@
#define WIDTH 420
#define HEIGHT 360
#define X_MIN -1.0
#define X_MAX 1.0
#define Y_MIN -1.0
#define Y_MAX 1.0
#define X_MIN -2.0
#define X_MAX 1.1
#define Y_MIN -1.3
#define Y_MAX 1.3
#define SIZE (WIDTH * HEIGHT)
@@ -47,7 +47,7 @@ int main() {
/////////////////////
void cx_print(Complex z) {
printf("%f + %f i", z.real, z.imag);
printf("%f + %f i\n", z.real, z.imag);
}
static inline Complex cx_square(Complex z) {
@@ -72,11 +72,15 @@ static inline Complex f(Complex z, Complex c) {
// return iteration count, MAX_DEPTH if diverge
int diverge(Complex c) {
int counter = 0;
int depth = 0;
Complex z = {0.0, 0.0};
for (z = f(z, c); cx_abs(z) < 2; counter++)
if (counter > MAX_DEPTH) return MAX_DEPTH;
return counter;
while (depth < MAX_DEPTH) {
z = f(z, c);
if (cx_abs(z) > 2)
return depth;
depth++;
}
return MAX_DEPTH;
}
Color color_map(int depth) {