Skip to content

Instantly share code, notes, and snippets.

@panzi
Created November 10, 2013 04:40

Revisions

  1. panzi created this gist Nov 10, 2013.
    30 changes: 30 additions & 0 deletions mandelbrot.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #include <stdio.h>
    #include <complex.h>
    #define dc double complex
    dc
    Y(dc
    V,
    dc B,dc c){
    return
    (cabs (V)<6)?(c?Y(V *V+
    B,B,c-1):c):(2+c-4*cpow
    (cabs(V),-0.4))/255;}int
    main (){unsigned int w=1920, h=
    1080, C= w*h,S =C*3+26,X,A,n=C>9?9:
    C;FILE*f= fopen("M.bmp","wb");if(!f)
    return 1;char buf[]={66,77,S&255,(S>>
    8)&255,(S>>16)&255,S>>24,0,0,0,0,26,0,0
    ,0,12,0,0,0,w&255,w>>8,h&255,h>>8,1,0,24,0};fwrite(buf,
    26,1,f);for(X=0;X<C;++X){dc T=0,t;for(A=0;
    A<n;++A){t=Y(0,(A%3/3.+X%w+(X/w+A/3/3.-
    h/2) /1*I)*2.5/h-2.7,255);T+=t*t;}T/=
    9; buf [0]=T*80+cpow(T,9)*255-950*
    cpow(T,99);buf[1]=T*70-880*
    cpow(T,18)+701*cpow(T,9);
    buf[2]=T*cpow(255,(1-cpow
    (T, 45) *2));fwrite (buf
    ,3,1,f);}
    fclose(f);
    return
    0 ;
    }