#include #include #include #include "project.h" /**************************************************************** * Reads pairs of points from stdin and outputs a n*m * * image showing the positions of the points. * * 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) { //reads in a point int c; while( TRUE ) { 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[]) { int n = 100; int m = 100; double s; int i, j, k; struct point *source; int nsource, allocated; if (argc <= 1 || (n = atoi(argv[1])) <= 0 ) { fprintf(stderr,"\ Useage is....\n"); return(EXIT_FAILURE); } if (n==1) n=2; m = n; if (argc > 2) m = atoi(argv[2]); 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); for(k=0; k 255 ? 255 : s ); } } free(source); return(EXIT_SUCCESS); }