home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / testgaug.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  4KB  |  155 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. //    Driver program for silly gauge plotter.
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #include "mono.h"
  19. #include "key.h"
  20. #include "gr.h"
  21.  
  22. #define NUM_LINES 10
  23.  
  24. typedef struct line {
  25.     float    x1,y1,x2,y2;
  26.     int    color;
  27. } line;
  28.  
  29. float    X1vec,Y1vec,X2vec,Y2vec;
  30. float    X1acc,Y1acc,X2acc,Y2acc;
  31. line    Line;
  32. int    Line_index;
  33.  
  34. // ---------------------------------------------------------------------------------
  35. // Return a random number in the range lo..hi-1
  36. int rrand(int lo,int hi)
  37. {
  38.  
  39.     return (rand() * (hi-lo)) / RAND_MAX + lo;
  40.  
  41. }
  42.  
  43. // ---------------------------------------------------------------------------------
  44. void create_random_line(void)
  45. {
  46.     line    *lp;
  47.  
  48.     lp = &Line;
  49.  
  50.     lp->x1 = rrand(0,grd_curcanv->cv_bitmap.bm_w);
  51.     lp->y1 = rrand(0,grd_curcanv->cv_bitmap.bm_h);
  52.  
  53.     lp->x2 = rrand(0,grd_curcanv->cv_bitmap.bm_w);
  54.     lp->y2 = rrand(0,grd_curcanv->cv_bitmap.bm_h);
  55.  
  56.     lp->color = 15;
  57. }
  58.  
  59. // ---------------------------------------------------------------------------------
  60. void gauge_init(void)
  61. {
  62.     line    *lp;
  63.  
  64.     Line_index = 0;
  65.     lp = &Line;
  66.  
  67.     create_random_line();
  68.     X1vec = 0.1;
  69.     Y1vec = 0.2;
  70.     X2vec = 0.3;
  71.     Y1vec = 0.4;
  72.  
  73.     X1acc = 0.003;
  74.     Y1acc = 0.004;
  75.     X2acc = 0.005;
  76.     Y2acc = 0.003;
  77.  
  78.     gr_setcolor(lp->color);
  79.     gr_line(fl2f(lp->x1),fl2f(lp->y1),fl2f(lp->x2),fl2f(lp->y2));
  80.  
  81.     Line_index++;
  82. }
  83.  
  84. // ---------------------------------------------------------------------------------
  85. void gauge_frame(void)
  86. {
  87.     float    x1,y1,x2,y2;
  88.  
  89.     line    *clp;
  90.     int    max_x,max_y;
  91.  
  92.     // Create new line at Line_index.
  93.     clp = &Line;
  94.  
  95.     x1 = clp->x1 + X1vec;
  96.     y1 = clp->y1 + Y1vec;
  97.  
  98.     x2 = clp->x2 + X2vec;
  99.     y2 = clp->y2 + Y2vec;
  100.  
  101.     X1vec += X1acc;
  102.     Y1vec += Y1acc;
  103.  
  104.     X2vec += X2acc;
  105.     Y2vec += Y2acc;
  106.  
  107.     max_x = grd_curcanv->cv_bitmap.bm_w;
  108.     max_y = grd_curcanv->cv_bitmap.bm_h;
  109.  
  110.     if (x1 > max_x) {        X1vec = 0;        x1 = clp->x1;    X1acc = -X1acc;    }
  111.  
  112.     if (y1 > max_y) {        Y1vec = 0;        y1 = clp->y1;    Y1acc = -Y1acc;    }
  113.  
  114.     if (x2 > max_x) {        X2vec = 0;        x2 = clp->x2;    X2acc = -X2acc;    }
  115.  
  116.     if (y2 > max_y) {        Y2vec = 0;        y2 = clp->y2;    Y2acc = -Y2acc;    }
  117.  
  118.     // now check min
  119.     if (x1 < 0) {        X1vec = 0;        x1 = clp->x1;    X1acc = -X1acc;    }
  120.  
  121.     if (y1 < 0) {        Y1vec = 0;        y1 = clp->y1;    Y1acc = -Y1acc;    }
  122.  
  123.     if (x2 < 0) {        X2vec = 0;        x2 = clp->x2;    X2acc = -X2acc;    }
  124.  
  125.     if (y2 < 0) {        Y2vec = 0;        y2 = clp->y2;    Y2acc = -Y2acc;    }
  126.  
  127.  
  128.     clp->x1 = x1;
  129.     clp->y1 = y1;
  130.     clp->x2 = x2;
  131.     clp->y2 = y2;
  132.     clp->color = (clp->color + 1) % 256;
  133.  
  134.     gr_setcolor(clp->color);
  135.     gr_line(fl2f(x1),fl2f(y1),fl2f(x2),fl2f(y2));
  136.     Line_index++;
  137.     if (Line_index >= NUM_LINES)
  138.         Line_index = 0;
  139.  
  140. }
  141.  
  142. // ---------------------------------------------------------------------------------
  143. // Do a gauge in the current canvas
  144. void gauge_test(void)
  145. {
  146.     int    i;
  147.  
  148.     gauge_init();
  149.  
  150.     for (i=0; i<10000; i++)
  151.         gauge_frame();
  152. }
  153.  
  154.  
  155.