/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH, 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; & CC Bordeianu, Univ Bucharest, 2007 Support by National Science Foundation */ // film.c: Ballistic deposition simulation (fractal) // Plot data without connecting datapoints with lines #include #include // if you don't have drand48 uncomment the following two lines #define drand48 1.0/RAND_MAX*rand #define srand48 srand #define max 30000 // number of iterations #define seed 68111 // seed for number generator main() { int i, hit[200], r; FILE *output; // save data in film.dat output= fopen("film.dat","w"); srand48(seed); // clear array for (i = 0; i<200; i++) hit[i]= 0; for (i = 1; i<= max; i++) { r= (int)(199*drand48()); // r = 0..199 if ((hit[r] >= hit[r-1]) && (hit[r] >= hit[r+1])) hit[r]++; else if (hit[r-1] > hit[r+1]) hit[r]= hit[r-1]; else hit[r]= hit[r+1]; fprintf(output, "%d\t%d\n", r, hit[r]); } printf("data stored in film.dat\n"); fclose(output); }