The Mandelbrot Set is calculated by repeating:
z = z^2 + c;
until the absolute value of z (distance from 0) is greater than say 4,
where z and c are complex numbers, c is the coordinates of the point being calculated.
Let z be a + bi and c = e + fi, the calculation becomes:
z = (a+bi)^2 + (e+fi)
z = a^2 + 2abi - b^2 + e + fi
or
a = a^2 - b^2 + e
b = 2ab + f
The test condition,
a^2 + b^2 > 4
is changed here to the equivalent
a^2 > 4 - b^2
in this code.
Replacing all the sneaky code with more traditional structures, we get:
float o=0.075; /* distance between pixels */
float h=1.5; /* imag component of c */
float T; /* real component of c */
float r; /* O squared */
float O; /* imag component of z */
float l; /* I squared */
float I; /* real component of z */
int _; /* iteration count */
int L=80 /* max iterations & line width */
int s=3200; /* total "pixels": 80*40 */
main(){
while (s>0) { /* lines 4 & 6 */
r = O * O;
l = I * I;
_++;
if (4-r<l || _==L) {
/* line 6 above ends here, next is line 7 */
s--; _--;
if (s%L==0) {
write(1,"\n",1);
} else {
if (_<L) {
write(1,_%6+"123456",1);
} else {
write(1," ",1);
}
}
/* line 8: */
O = I = l = _ = r = 0;
T += o/2;
}
/* line 10: z=z^2+c */
O = I * 2 * O + h;
I = l + T - r;
/* this next bit is line 5 */
if (s%L) {
h -= o;
T = -2;
}
}
}
The main loop has been sucked into the iteration loop, updating its variables when each pixel is finished.