#include #include #include /******************************************************** * Takes co-ordinates of points in from stdin * * out writes to stdout a pgm file of the * * fourier transform * * Based on fourier.c by Stuart Levy from * * "Quasicrystal and Geometry" by Marjorie Senchal * * David Longbottom * ********************************************************/ struct point { double x,y; }; int getnumber (double *v) { int c; for(;;) { switch (c = getchar()) { case' ':case'\t':case'\n':case'\r': case',':case'(':case')':case'{':case'}':case'[':case']': continue; //ignore whitespace etc case'#': //commented-out line while((c = getchar()) != '\n' && c != EOF); continue; default: ungetc(c,stdin); return (scanf("%lf",v) == 1); } } } int main (int argc, char *argv[]) { double srange = 100.0; int n = 100; int m = 100; double brightness = 1; double scale; int i, j, k; int i1, j1; struct point s, *source; double re, im; int nsource, allocated; double dot, mag, maxmag; if (argc <= 1 || (n = atoi(argv[1])) <= 0 ) { fprintf(stderr,"\ Useage is:\n%s n [m] [srange] [brightness] < data points\n",argv[0]); return(EXIT_FAILURE); } if (n==1) n=2; m = n; if (argc > 2) m = atoi(argv[2]); if (argc > 3) srange = atof(argv[3]); if (argc > 4) brightness = atof(argv[4]); allocated = 15; source = (struct point *)malloc(allocated * sizeof(struct point)); nsource = 0; while (getnumber(&source[nsource].x) && getnumber(&source[nsource].y)) { nsource++; if(nsource >= allocated) { allocated *=2; source = (struct point *)realloc(source,allocated*sizeof(struct point)); } } fprintf(stderr,"%d light sources.\n",nsource); scale = nsource > 0 ? brightness * 256 / nsource : 1; printf("P5\n%d %d\n255\n",n,m); for(k=0; k= 255 ? 255:(int)mag); if(maxmag < mag) maxmag = mag; } } if (maxmag > 0 ) fprintf(stderr,"Max mag %.1f; max brightness which won't saturate:%g\n",maxmag,brightness*256/maxmag); free(source); return(EXIT_SUCCESS); }