summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-04-05 16:10:27 +0200
committertomsmeding <tom.smeding@gmail.com>2017-04-05 16:10:27 +0200
commit6354733cbf391f996c07b79be8466f66990ecd24 (patch)
treeeef5d7ca64a864b119811a29b2582d432dcc42c2
parentce3318404a44f39fc51c951643e18caa734c386d (diff)
Better gradient and filename as param
-rw-r--r--attract.c30
1 files 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);
}