home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / djdev108.zip / SAMPLES / GRTASK / MAIN.CC next >
C/C++ Source or Header  |  1991-03-20  |  1KB  |  80 lines

  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <pc.h>
  4. #include "Task.h"
  5.  
  6. int X;
  7. int Y;
  8.  
  9. void lines1()
  10. {
  11.   for (int i=0; i<GrMaxX(); i++)
  12.   {
  13.     GrLine(X, Y, i, GrMaxY(), i | GrXOR);
  14.     GrLine(X, Y, i, 0, i | GrXOR);
  15.     Yield();
  16.   }
  17. }
  18.  
  19. void lines2()
  20. {
  21.   for (int i=0; i<GrMaxY(); i++)
  22.   {
  23.     GrLine(X, Y, GrMaxX(), i, i | GrXOR);
  24.     GrLine(X, Y, 0, i, i | GrXOR);
  25.     Yield();
  26.   }
  27. }
  28.  
  29. void setup()
  30. {
  31.   int i;
  32.   for (i=2; i<256; i++)
  33.   {
  34.     GrSetColor(i, random()%50, random()%50, random()%50);
  35.     Yield();
  36.   }
  37.   int t_r, t_g, t_b;
  38.   int o_r=0, o_g=0, o_b=0;
  39.   int j=0;
  40.   while(!kbhit())
  41.   {
  42.     if (j == 0)
  43.     {
  44.       t_r = (random()%256000 - o_r) / 1000;
  45.       t_g = (random()%256000 - o_g) / 1000;
  46.       t_b = (random()%256000 - o_b) / 1000;
  47.       j = 1000;
  48.     }
  49.     for (i=0; i<8; i++)
  50.       GrSetColor(1<<i, o_r/1000, o_g/1000, o_b/1000);
  51.     o_r += t_r;
  52.     o_g += t_g;
  53.     o_b += t_b;
  54.     j--;
  55.     Yield();
  56.   }
  57. }
  58.  
  59. main()
  60. {
  61.   srandom(time(0));
  62.   GrSetMode(GR_default_graphics);
  63.  
  64.   X = GrMaxX()/3;
  65.   Y = GrMaxY()/3;
  66.  
  67.   new Task(); // this task
  68.  
  69.   new Task((TaskProc *)lines1);
  70.   new Task((TaskProc *)lines2);
  71.   Wait();
  72.  
  73.   new Task((TaskProc *)setup);
  74.   Wait();
  75.  
  76.   getkey();
  77.   GrSetMode(GR_default_text);
  78. }
  79.  
  80.