ASCII Art: Mandelbrot Fractal

Mandelbrot Set ASCII
Click to zoom in



At the top of Ken Perlin’s homepage there is a strange C code:

COMPILE THIS:
main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}

I couldn't resist to test it. I just modified it a little bit to make it more readable:

int main(int argc, char** argv)
{
  int k = 2;
  float i,j,r,x,y=-16;
  while (puts(""), y++<15)
    for (x=0; x++<84; putchar(" .:-;!/>)|&IH%*#"[k&15]))
      for (i=k=r=0; 
           j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111; 
           r=j);
  return 0;
}

The result of the execution of this code ? Simply the Mandrelbrot set in ASCII ;)

[via]

3 thoughts on “ASCII Art: Mandelbrot Fractal”

  1. Korvin77

    Thanks for posting. That’s why I love C… but we all understand that this is the dark side of the force 😀

  2. KevinRulz

    I love C too — better than fairy land c++

    i belong to and love the dark side 🙂

Comments are closed.