Skip to content

Instantly share code, notes, and snippets.

@panzi
Created November 10, 2013 04:40
Show Gist options
  • Save panzi/7393912 to your computer and use it in GitHub Desktop.
Save panzi/7393912 to your computer and use it in GitHub Desktop.
gcc -lm -Wall -Werror -Wextra -pedantic -std=c99 -O3 -o mandelbrot mandelbrot.c original: http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python/
#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 ;
}
@hho
Copy link

hho commented Jun 8, 2014

...and for C newbies like myself: In Ubuntu, the gcc call given above doesn't work -- the -lm has to go at the very end (library has to be stated after the file that uses them, because --as-needed is the default for ld now)...

Copy link

ghost commented Jul 21, 2015

Thanks, nice tip!

@frehseg
Copy link

frehseg commented Nov 12, 2018

Amazing, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment