_ _
| |_ ___ __| |____ ___ _ _
| __/ _ \/ _` |_ / / _ \ | | |
| || __/ (_| |/ / | __/ |_| |
\__\___|\__,_/___(_)___|\__,_|
dreamer.c
//
// dreamer.c - written by Ted Burke - 1-Apr-2026
//
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <complex.h>
#define W 1600
#define H 1600
uint8_t p[H][W];
double randf()
{
return 2.0 * (rand() * 1.0 / RAND_MAX - 0.5);
}
int main()
{
complex double c, c0, z, z0;
complex double a_tl, a_tr, a_bl, a_br, a, b;
double pxw, e;
int y, x, n;
double xx, yy;
// Set parameters
c0 = 0.625 - I*0.4;
z0 = 0;
pxw = 0.0025;
a_tl = randf();
a_tr = randf();
a_bl = randf();
a_br = randf();
// Calculate pixel values
for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x)
{
c = c0;
z = z0 + pxw * (x-W/2 + I*(y-H/2));
for (n=25 ; n && cabs(z)<4.0 ; --n)
{
xx = x * 1.0 / W;
yy = y * 1.0 / H;
a = yy*(xx*a_tl + (1-xx)*a_tr)
+ (1-yy)*(xx*a_bl + (1-xx)*a_br);
b = pow(cabs(z),a) * cexp(I*carg(z)*2);
z = b - c;
}
p[y][x] = 10 * n;
}
// Write pixel data to PGM file
FILE *f = fopen("image.pgm", "w");
fprintf(f, "P2\n%d %d\n255\n", W, H);
for (y=0 ; y<H ; ++y)
{
for (x=0 ; x<W ; ++x)
{
fprintf(f, "%03d ", p[y][x]);
}
fprintf(f, "\n");
}
fclose(f);
}