home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / GRAPHICS / kwsaver.lzh / kwsaver_lines.c < prev    next >
C/C++ Source or Header  |  1994-05-05  |  2KB  |  71 lines

  1. /* kwsaver_lines.c                       */
  2. /* by Joel Mathew Hegberg                */
  3. /* a simple kwsaver screen-saver program */
  4. /* which runs on any type screen.        */
  5.  
  6. /* Note: there is no exit to this program... it is killed when */
  7. /*       a signal is sent to it.  This technique may be used   */
  8. /*       since this program uses no K-Windows graphics buffers */
  9. /*       and requires no deinitialization before exiting...    */
  10. /*       otherwise, a signal trap would have to be used.       */
  11.  
  12. #include <stdio.h>
  13.  
  14. #define PATH 1
  15.  
  16. main()
  17. {
  18.     int x1,y1,x2,y2,dx1,dy1,dx2,dy2,mx1,my1,mx2,my2,counter,color,maxcolors;
  19.     
  20.     maxcolors=Get_Num_Colors(PATH);    /* # of colors available on screen */
  21.     x1=50; x2=400; y1=100; y2=200;    /* line starting coordinates */
  22.     dx1=2; dx2=-3; dy1=-1; dy2=2;    /* line movement variables */
  23.     mx1=1; my1=1; mx2=3; my2=2;        /* multipliers */
  24.     counter=0; color=1;
  25.         
  26.     while(1)
  27.     {
  28.         FColor(PATH,color);        /* set line color */
  29.         SetDPtr(PATH,x1,y1);    /* start coordinate */
  30.         Line(PATH,x2,y2);        /* draw the line */
  31.         
  32.         /* next, move the line according to directionals */
  33.         x1+=dx1*mx1; x2+=dx2*mx2; y1+=dy1*my1; y2+=dy2*my2;
  34.         
  35.         /* now, check if any directionals need to be reversed */
  36.         if (x1<0 || x1>639)
  37.         {
  38.             x1-=dx1*mx1;
  39.             dx1=-dx1;
  40.             if (++mx1>5) mx1=1;
  41.         }
  42.         if (x2<0 || x2>639)
  43.         {
  44.             x2-=dx2*mx2;
  45.             dx2=-dx2;
  46.             if (++mx2>5) mx2=1;
  47.         }
  48.         if (y1<0 || y1>207)
  49.         {
  50.             y1-=dy1*my1;
  51.             dy1=-dy1;
  52.             if (++my1>5) my1=1;
  53.         }
  54.         if (y2<0 || y2>207)
  55.         {
  56.             y2-=dy2*my2;
  57.             dy2=-dy2;
  58.             if (++my2>5) my2=1;
  59.         }
  60.         
  61.         if (++counter>500)    /* after 500 lines, clear the screen */
  62.         {
  63.             Clear(PATH);
  64.             counter=0;
  65.         }
  66.         
  67.         if (++color>=maxcolors) color=1;    /* select next color */
  68.     }
  69. }
  70.  
  71.