#include #include #include #include #define MAXTIME (200) #define NPATCH 200 #define MAXIPAT 100 #define NCONS 30 #define ALPHA 0.05 #define KK 1.0 #define MIN_RESRCE 0.2 #define CONFRAC 0.1 #define MOVECOST 0.1 #define TIMECOST 0.01 #define STAYTIME 20 #define MOVING_AVE 0.5 struct patch_def { double k; double alpha; double size; } patches[NPATCH]; struct con_def { double beta; int mvflag; struct patch_def *patch; int patnum; double time; double lunch; double inrate; } consumer[NCONS]; double sqrt(double); void InitSeed(void); void InitCon(struct con_def *); void InitPatch(struct patch_def *); void GrowPatch(struct patch_def *); void Feed(struct con_def *); void Move(struct con_def *); void Spit_EPS_Header(FILE *, int, int); void Spit_EPS_Row(FILE *, struct patch_def *, struct con_def *); void Spit_EPS_Trailer(FILE *); int main(void) { int ipat, icon, ttt, counts[NPATCH]; FILE *fopen(const char *, const char *), *fileid; InitSeed(); fileid = fopen("patches.eps","w"); Spit_EPS_Header(fileid,NPATCH,MAXTIME); for(icon=0;icontm_sec+1)*(preztime->tm_min+1)* (preztime->tm_hour+1)*(preztime->tm_year)*(preztime->tm_year)); if(seed%2==0) seed++; srand48(seed); } void InitCon(struct con_def *con) { int i; (*con).beta = CONFRAC; con->mvflag = 0; i = drand48() * MAXIPAT; con->patch = &patches[i]; con->patnum = i; con->time = 0.0; con->lunch = -MOVECOST; con->inrate = 0.0; } void InitPatch(struct patch_def *pat) { pat->k = KK; pat->alpha = ALPHA; pat->size = KK; } void GrowPatch(struct patch_def *pat) { pat->size += pat->alpha * pat->size * (1.0-pat->size/pat->k); if(pat->size>pat->k) pat->size = pat->k; } void Feed(struct con_def *con) { double eaten; eaten = con->beta * con->patch->size; con->patch->size -= eaten; if(con->patch->sizemvflag = 1; con->lunch += eaten; con->time += 1.0; } void Move(struct con_def *con) { con->lunch -= (TIMECOST*con->time+MOVECOST); con->inrate = MOVING_AVE*(con->lunch/con->time) + (1.0-MOVING_AVE)*con->inrate; con->time = 0.0; con->mvflag = 0; if(con->patnum!=NPATCH-1) { con->patch++; con->patnum++; } else con->beta = 0.0; /* This value removes consumer's effect at end, but mucks up their intake values...(if used) */ } void Spit_EPS_Header(FILE *fileid, int width, int length) { float neww, newl, rat; float xorigin, yorigin; neww = (float)width; newl = (float)length; if(neww>600.0) { rat = 600.0/neww; neww = 600.0; newl = rat*newl; } if(newl>780.0) { rat = 780.0/newl; newl = 780.0; neww = rat*neww; } /* 8.5x11 page with no margins is 612x792 points */ xorigin = (612 - neww)/2.0; yorigin = (792 - newl)/2.0; /* defines compliance */ fprintf(fileid,"%%!PS-Adobe-2.0 EPSF-2.0\n"); /* defines size of image */ fprintf(fileid,"%%%%BoundingBox: %f %f %f %f\n", xorigin, yorigin,xorigin+neww,yorigin+newl); /* save present graphics state */ fprintf(fileid,"gsave\n"); /* put box around image */ fprintf(fileid,"%f %f moveto\n",xorigin-1,yorigin-1); fprintf(fileid,"%f %f lineto\n",xorigin-1,yorigin+newl+1); fprintf(fileid,"%f %f lineto\n",xorigin+neww+1,yorigin+newl+1); fprintf(fileid,"%f %f lineto\n",xorigin+neww+1,yorigin-1); fprintf(fileid,"%f %f lineto\n",xorigin-1,yorigin-1); fprintf(fileid,"stroke\n\n",xorigin-1,yorigin-1); /* define procedure "bufstr" to read strings of "width" characters */ fprintf(fileid,"/bufstr %d string def\n\n",width); /* move to origin of image */ fprintf(fileid,"%f %f translate\n",xorigin,yorigin); /* define the scale (default is 1 pt I guess) */ fprintf(fileid,"%f %f scale\n\n",neww,newl); /* width, height, and number of bits per pixel */ fprintf(fileid,"%d %d 8\n",width,length); /* a matrix definition that I don't understand */ fprintf(fileid,"[%d 0 0 %d 0 %d]\n",width,-length,length); /* guidelines on how to read the image data */ fprintf(fileid,"{currentfile bufstr readhexstring pop} bind image\n"); } void Spit_EPS_Row(FILE *fileid, struct patch_def *pat, struct con_def *con) { int i, j; /* for(i=0;ipnum; outcnt[j] = 0; } */ for(i=0;i