From 6354733cbf391f996c07b79be8466f66990ecd24 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 5 Apr 2017 16:10:27 +0200 Subject: Better gradient and filename as param --- attract.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/attract.c b/attract.c index 66fbee4..4526d0e 100644 --- a/attract.c +++ b/attract.c @@ -35,16 +35,12 @@ struct colour{ unsigned char r,g,b; }; -__attribute__((unused)) -static struct colour make_colour(int index){ - static const struct colour clr_base[]={ - {255,100,100}, {100,255,100}, {100,100,255}, - {200,200,30}, {200,30,200}, {30,200,200}, - {100,100,100}, {200,200,200} - }; - static const int nbase=sizeof(clr_base)/sizeof(clr_base[0]); - - return clr_base[index%nbase]; +static struct colour make_colour(double complex z){ + static const double N=3; + double norm=cabs(z); + if(norm>N)norm=N; + int clrv=(int)(norm/N*255); + return (struct colour){clrv,clrv,clrv}; } struct config{ @@ -108,8 +104,7 @@ static void* thread_entry(void *arg_vp){ // struct colour clr=make_colour(bi); } - unsigned char clrv=(int)(cabs(z)/3*255)%256; - struct colour clr={clrv,clrv,clrv}; + struct colour clr=make_colour(z); img[3*(iy*cfg.width+ix)+0]=clr.r; img[3*(iy*cfg.width+ix)+1]=clr.g; img[3*(iy*cfg.width+ix)+2]=clr.b; @@ -126,10 +121,15 @@ int main(int argc,char **argv){ .exponent=8.5 }; - assert(argc==1||argc==2); - if(argc==2){ + if(argc>=2){ cfg.exponent=strtod(argv[1],NULL); } + const char *fname; + if(argc>=3){ + fname=argv[2]; + } else { + fname="out.png"; + } unsigned char img[cfg.width*cfg.height*3]; @@ -169,5 +169,5 @@ int main(int argc,char **argv){ } } - lodepng_encode_file("out.png",img,cfg.width,cfg.height,LCT_RGB,8); + lodepng_encode_file(fname,img,cfg.width,cfg.height,LCT_RGB,8); } -- cgit v1.2.3