home *** CD-ROM | disk | FTP | other *** search
/ Carousel / CAROUSEL.cdr / mactosh / demo / inuse.sit / inuse.c next >
C/C++ Source or Header  |  1986-04-24  |  3KB  |  96 lines

  1. /* Program INUSE.C for the Megamax C compiler */
  2. /* (C) 1986 William Woody, commercial rights reserved */
  3.  
  4. /* If you think this program is cute, please send me computer mail and tell */
  5. /* me so!  I personally think it's a cute hack, myself, but what do I know. */
  6.  
  7. /* Though I don't believe this program has any commercial value, (or ANY */
  8. /* monitary value whatsoever), I have reserved commercial rights anyways.*/
  9. /* Silly me...  But if you want to give it to your friends, please leave */
  10. /* my name on the darn thing; I need to feel appreciated.  */
  11.  
  12. #include <stdio.h>
  13. #include <qdvars.h>        /* What they don't tell you is that you need to */
  14.                         /* include this for the SRAND macro to work... */
  15.  
  16. extern int random();
  17. extern char *malloc();
  18.  
  19. #define MAXX 480
  20. #define MAXY 300
  21. #define MAXM 400
  22.  
  23. struct foo {
  24.     double a,b;            /* This is a point which gets to fly around */
  25.     struct foo *next;
  26. };
  27.  
  28. main()
  29. {
  30.     int numb,n,x,done = 0;
  31.     struct foo *top,*ptr,*ptr2;
  32.     double mx,my,nx,ny;
  33.     struct {
  34.         int top,left,bottom,right;
  35.     } r;
  36.     long seed;
  37.  
  38.     _autowin("Inuse");    /* Megamax C instruction to create a default window */
  39.     setrect(&r,0,0,512,342);
  40.     
  41.     eraserect(&r);
  42.     moveto(10,10);
  43.     textfont(0);
  44.     textsize(12);
  45.     printf("Inuse program ⌐1985 by William Woody, commercial rights reserved\n");
  46.     printf("To halt the program, press the mouse button.\n");
  47.  
  48.     getdatetime(&seed);
  49.     srand(seed);            /* Seed the random number generator */
  50.  
  51.     while (!done) {
  52.         numb = (random() & 3) + 2;  /* Number of points generated */
  53.         x = 0;
  54.         top = ptr = (struct foo *)malloc(sizeof(struct foo));
  55.         while (x++ != numb)
  56.             ptr = (ptr->next = (struct foo *)malloc(sizeof(struct foo)));
  57.         ptr = (ptr->next = top);
  58.         mx = 0;
  59.         my = 0;
  60.         nx = 9999999.0;        /* Large numbers for finding minimum value */
  61.         ny = 9999999.0;
  62.         do {
  63.             ptr->a = (double)random();
  64.             if (ptr->a > mx) mx = ptr->a;
  65.             if (ptr->a < nx) nx = ptr->a;
  66.             ptr->b = (double)random();
  67.             if (ptr->b > my) my = ptr->b;
  68.             if (ptr->b < ny) ny = ptr->b;
  69.             ptr = ptr->next;
  70.         } while (ptr != top);        /* Make up the points and create a */
  71.         do {                        /* circularly linked list of them */
  72.             ptr->a = (ptr->a - nx) * MAXX / (mx - nx);
  73.             ptr->b = (ptr->b - ny) * MAXY / (my - ny);
  74.             ptr = ptr->next;
  75.         } while (ptr != top);
  76.         n = 0;
  77.         moveto((int)ptr->a,(int)ptr->b);
  78.         while (n++ != MAXM * numb) {    /* Now, move the points around */
  79.             ptr->a = (ptr->a * 40 + ptr->next->a) / 41;
  80.             ptr->b = (ptr->b * 40 + ptr->next->b) / 41;
  81.             lineto((int)ptr->a,(int)ptr->b);
  82.             ptr = ptr->next;
  83.             if (button()) {        /* Halt program when button is pressed */
  84.                 done = 1;
  85.                 break;
  86.             }
  87.         }
  88.         ptr = top;                /* Clean up the circular linked list */
  89.         do {
  90.             ptr = (ptr2 = ptr)->next;
  91.             free(ptr2);
  92.         } while (ptr != top);
  93.  
  94.         eraserect(&r);
  95.     }
  96. }