home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / devcon / milan_1991 / devcon91.2 / tiga / demos / lines.c < prev    next >
C/C++ Source or Header  |  1992-09-01  |  2KB  |  124 lines

  1. #include <stdio.h>
  2. #include <a2410/typedefs.h>
  3. #include <a2410/devtiga.h>
  4. #include <clib/a2410_protos.h>
  5. #include <math.h>
  6.  
  7. BOOL TIGA_Init(void);
  8. void TIGA_Close(void);
  9. void TIGA_Break(void);
  10. void TIGA_SetRandPalet(void);
  11.  
  12. void    LinesDemo(void);
  13. /* ================================================================================ */
  14. void main(int argc, char **argv)
  15. {
  16.     if (TIGA_Init())
  17.      {
  18.         onbreak(TIGA_Break);
  19.         TIGA_SetRandPalet();
  20.         LinesDemo();
  21.         TIGA_Close();
  22.      }
  23. }
  24.  
  25. /* ------------------------------------------------------------------------------- */
  26.  
  27. void    LinesDemo()
  28. {
  29.     int x1,y1,x2,y2;
  30.     int x1v,y1v,x2v,y2v;
  31.     int i,c;
  32.     CONFIG    config;
  33.     
  34.     get_config(&config);
  35.  
  36.     c = 0;
  37.     x1v = y1v = x2v = y2v = 0;
  38.     x1 = x2 = config.mode.disp_hres/2;
  39.     y1 = y2 = config.mode.disp_vres/2;
  40.  
  41.     for (;;)
  42.     {
  43.         c = ((c)%(config.mode.palet_size-1))+1;
  44.         set_fcolor(c);
  45.  
  46.         x1v = x1v/2 + (rand() & 15) - 7;
  47.         y1v = y1v/2 + (rand() & 15) - 7;
  48.         x2v = x2v/2 + (rand() & 15) - 7;
  49.         y2v = y2v/2 + (rand() & 15) - 7;
  50.  
  51.         i = 300;
  52.  
  53.         while(i--)
  54.         {
  55.             chkabort();
  56.             x1 += x1v;
  57.             y1 += y1v;
  58.             x2 += x2v;
  59.             y2 += y2v;
  60.  
  61.             if (x1 < 0)
  62.                 {
  63.                 x1 = - x1;
  64.                 x1v = - x1v;
  65.                 y1v += (rand() % 5) - 2;
  66.                 }
  67.  
  68.             if (y1 < 0)
  69.                 {
  70.                 y1 = - y1;
  71.                 y1v = - y1v;
  72.                 x1v += (rand() % 5) - 2;
  73.                 }
  74.  
  75.             if (x1 >= config.mode.disp_hres)
  76.                 {
  77.                 x1 = 2*config.mode.disp_hres - x1 - 2;
  78.                 x1v = - x1v;
  79.                 y1v += (rand() % 5) - 2;
  80.                 }
  81.  
  82.             if (y1 >= config.mode.disp_vres)
  83.                 {
  84.                 y1 = 2*config.mode.disp_vres - y1 - 2;
  85.                 y1v = -y1v;
  86.                 x1v += (rand() % 5) - 2;
  87.                 }
  88.  
  89.             if (x2 < 0)
  90.                 {
  91.                 x2 = - x2;
  92.                 x2v = - x2v;
  93.                 y2v += (rand() % 5) - 2;
  94.                 }
  95.  
  96.             if (y2 < 0)
  97.                 {
  98.                 y2 = - y2;
  99.                 y2v = - y2v;
  100.                 x2v += (rand() % 5) - 2;
  101.                 }
  102.  
  103.             if (x2 >= config.mode.disp_hres)
  104.                 {
  105.                 x2 = 2*config.mode.disp_hres - x2 - 2;
  106.                 x2v = - x2v;
  107.                 y2v += (rand() % 5) - 2;
  108.                 }
  109.  
  110.             if (y2 >= config.mode.disp_vres)
  111.                 {
  112.                 y2 = 2*config.mode.disp_vres - y2 - 2;
  113.                 y2v = - y2v;
  114.                 x2v += (rand() % 5) - 2;
  115.                 }
  116.  
  117.             draw_line(x1, y1, x2, y2);
  118.  
  119.             /* synchronize(); */
  120.         }
  121.     }
  122. }
  123. /* --------------------------------------------------------------------------------- */
  124.