home *** CD-ROM | disk | FTP | other *** search
/ Aztec Shareware Collection / CHILDREN.ISO / firework / example.c < prev    next >
Text File  |  1990-01-27  |  1KB  |  48 lines

  1. /* 
  2.  * Simple example of a program to generate a data file for a round explosion 
  3.  * for EXPLOD.EXE.  Use a command similar to "cc example.c" to compile, and
  4.  * the command "example >circle.dat" to run.  Run EXPLOD.EXE with the command
  5.  * "explod circle.dat" to see the results.
  6.  */
  7.  
  8. rnd (maxval)
  9. {
  10. #   define MAX_RAND 32768       /* max value returned by rand() */
  11.     long l = (long) maxval * rand() / MAX_RAND;
  12.     return ((int) l);
  13. }
  14.  
  15. main ()
  16. {
  17. #   define XSIZE 200
  18. #   define YSIZE 120
  19.     int dest_x, dest_y;
  20.     int i = 0;
  21.  
  22.     /* Print the file header */
  23.     printf ("# EXPLOD DATA FILE generated by example.c\n");
  24.     printf ("300  # number of points\n");
  25.     printf (" 50  # number of frames\n");
  26.     printf ("  9  # gravity\n");
  27.     printf ("  0  # wind\n");
  28.     printf ("  2  # trail length\n");
  29.  
  30.     for (i=0; i<300; i++)   /* loop to generate 300 points */
  31.     {
  32.         /* Find a dest coordinate inside the ellipse of size (XSIZE, YSIZE) */
  33.         while (1)
  34.         {
  35.         /* Generate a point */
  36.             dest_x = rnd (2*XSIZE) - XSIZE;
  37.             dest_y = rnd (2*YSIZE) - YSIZE;
  38.  
  39.         /* Accept the point if it is within the oval */
  40.         if ((long) YSIZE * YSIZE * dest_x * dest_x  +  
  41.          (long) XSIZE * XSIZE * dest_y * dest_y  
  42.         <  (long) XSIZE * XSIZE * YSIZE * YSIZE)
  43.         break;
  44.         }
  45.     printf ("0 0  %d %d\n", dest_x, dest_y);
  46.     }
  47. }
  48.