Skip to content

Instantly share code, notes, and snippets.

@lukakostic
Last active March 17, 2020 04:32
Show Gist options
  • Save lukakostic/a9e5188cf41d00d3649b0e41c2085e87 to your computer and use it in GitHub Desktop.
Save lukakostic/a9e5188cf41d00d3649b0e41c2085e87 to your computer and use it in GitHub Desktop.
#include<cstdio>
#define D fputc(i*8,f) //colors (max = 248=31*8) with 31 iterations
main(){
int h=4000,w=4000,a=w*h,i; //resolution
FILE*f=fopen("img.ppm","wb");
fprintf(f,"P6\n%d %d\n255\n",w,h); //ppm header: P6 w h colorMax
for(;a--;i=31){ //iterations (31) per each pixel (x)
for(double t,x=.0,y=.0;x*x+y*y<4.&&i-->1;) //limit (4=2^2)
t=x*x-y*y+(a%w-w/2.)*.0006-.5, //x zoom (*.0006) & view (-.5)
y=2.*x*y+(a/w-h/2.)*.0006+.0, //y zoom (*.0006) & view (+.0)
x=t; //z=z^2+c (cx, cy = pixels scaled to view (-1.,1.) for 4k*4k)
D,D,D; //place r,g,b bytes
}}
@lukakostic
Copy link
Author

img

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