home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Moire / blank.c next >
Encoding:
C/C++ Source or Header  |  1994-10-18  |  4.3 KB  |  225 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <hardware/custom.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/dos_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include "/Garshnelib/Garshnelib_protos.h"
  19. #include "/Garshnelib/Garshnelib_pragmas.h"
  20.  
  21. #include "Moire.h"
  22. #include "/main.h"
  23. #include "//defs.h"
  24.  
  25. struct ModulePrefs
  26. {
  27.     LONG Mode;
  28.     LONG Depth;
  29.     LONG xSpeed;
  30.     LONG ySpeed;
  31.     LONG Trail;
  32.     LONG Lines;
  33.     LONG Cycle;
  34. };
  35.  
  36. extern struct ModulePrefs nP;
  37. extern __far struct Custom custom;
  38. Triplet *ColorTable = 0L;
  39.  
  40. #define RAND( base, offset ) (( LONG )( RangeRand( base ) + offset ))
  41.  
  42. LONG Blank( VOID *Prefs )
  43. {
  44.     LONG numCols, i, j, k, n, Trail, xSpeed, ySpeed, Wid, Hei, **cx, **cy, *dx;
  45.     LONG ToFrontCount = 0, RetVal = OK,    *dy, nl;
  46.     struct ModulePrefs *mP;
  47.     struct Screen *MoireScr;
  48.     struct Window *Wnd;
  49.     struct RastPort *rp;
  50.     struct ViewPort *vp;
  51.  
  52.     if( MoireWnd )
  53.         mP = &nP;
  54.     else
  55.         mP = ( struct ModulePrefs * )Prefs;
  56.  
  57.     xSpeed = mP->xSpeed;
  58.     ySpeed = mP->ySpeed;
  59.     nl = mP->Lines;
  60.     Trail = mP->Trail;
  61.  
  62.     cx = AllocVec( nl * sizeof( LONG * ), MEMF_CLEAR );
  63.     cy = AllocVec( nl * sizeof( LONG * ), MEMF_CLEAR );
  64.     dx = AllocVec( nl * sizeof( LONG ), MEMF_CLEAR );
  65.     dy = AllocVec( nl * sizeof( LONG ), MEMF_CLEAR );
  66.  
  67.     if( cx && cy )
  68.     {
  69.         for( k = 0; k < nl; k++ )
  70.         {
  71.             if(!( cx[k] = AllocVec( Trail * sizeof( LONG ), MEMF_CLEAR )))
  72.                 break;
  73.             if(!( cy[k] = AllocVec( Trail * sizeof( LONG ), MEMF_CLEAR )))
  74.                 break;
  75.         }
  76.     }
  77.         
  78.     MoireScr = OpenScreenTags( 0l, SA_DisplayID, mP->Mode, SA_Depth, mP->Depth,
  79.                               SA_Quiet, TRUE, SA_Behind, TRUE,
  80.                               SA_Overscan, OSCAN_STANDARD, TAG_DONE );
  81.     
  82.     if( cx && cy && dx && dy &&( k == nl )&& MoireScr )
  83.     {
  84.         rp = &( MoireScr->RastPort );
  85.         vp = &( MoireScr->ViewPort );
  86.         Wid = MoireScr->Width;
  87.         Hei = MoireScr->Height;
  88.         
  89.         numCols = 1 << rp->BitMap->Depth;
  90.         
  91.         SetRGB4( vp, 0, 0, 0, 0 );
  92.  
  93.         switch( mP->Cycle )
  94.         {
  95.         case 0:
  96.             ColorTable = RainbowPalette( MoireScr, 0L, 1L, 0L );
  97.             break;
  98.         case 1:
  99.             SetRGB4( vp, 1, RAND( 14, 1 ), RAND( 14, 1 ), RAND( 14, 1 ));
  100.             break;
  101.         case 2:
  102.             SetRGB4( vp, 1, 15, 15, 15 );
  103.             break;
  104.         case 3:
  105.             setCopperList( Hei, 1, vp, &custom );
  106.             break;
  107.         }
  108.         
  109.         for( k = 0; k < nl; k++ )
  110.         {
  111.             cx[k][1] = RAND( Wid - 2, 1 );
  112.             cy[k][1]= RAND( Hei - 2, 1 );
  113.             dx[k] = RAND( xSpeed, 1 );
  114.             dy[k] = RAND( ySpeed, 1 );
  115.         }
  116.         i = 0;
  117.         j = 0;
  118.         
  119.         Wnd = BlankMousePointer( MoireScr );
  120.         ScreenToFront( MoireScr );
  121.         
  122.         while( RetVal == OK )
  123.         {
  124.             if(!( ++ToFrontCount % 5 ))
  125.                 WaitTOF();
  126.  
  127.             if(!( ToFrontCount % 300 ))
  128.                 ScreenToFront( MoireScr );
  129.             
  130.             i = (i+1) % Trail;
  131.             n = (i+1) % Trail;
  132.             j = (j+1) % 255;
  133.             
  134.             if( !mP->Cycle )
  135.                 SetAPen( rp, ( j * ( numCols - 1 )) / 255 + 1 );
  136.             else
  137.                 SetAPen( rp, 1 );
  138.             
  139.             for( k = 0; k < nl; k++ )
  140.             {
  141.                 if( cx[k][i] >= Wid )
  142.                 {
  143.                     dx[k] = -1 * RAND( xSpeed, 1 );
  144.                     cx[k][i] = Wid-1;
  145.                 }
  146.                 else
  147.                     if( cx[k][i] < 0 )
  148.                     {
  149.                         dx[k] = RAND( xSpeed, 1 );
  150.                         cx[k][i] = 0;
  151.                     }
  152.                 if( cy[k][i] >= Hei )
  153.                 {
  154.                     dy[k] = -1 * RAND( ySpeed, 1 );
  155.                     cy[k][i] = Hei-1;
  156.                 }
  157.                 else
  158.                     if( cy[k][i] < 0 )
  159.                     {
  160.                         dy[k] = RAND( ySpeed, 1 );
  161.                         cy[k][i] = 0;
  162.                     }
  163.             }
  164.             
  165.             Move( rp, cx[0][i], cy[0][i] );
  166.             for( k = 1; k < nl; k++ )
  167.                 Draw( rp, cx[k][i], cy[k][i] );
  168.             if( nl > 2 )
  169.                 Draw( rp, cx[0][i], cy[0][i] );
  170.             
  171.             SetAPen( rp, 0 );
  172.             
  173.             Move( rp, cx[0][n], cy[0][n] );
  174.             for( k = 1; k < nl; k++ )
  175.                 Draw( rp, cx[k][n], cy[k][n] );
  176.             if( nl > 2 )
  177.                 Draw( rp, cx[0][n], cy[0][n] );
  178.             
  179.             for( k = 0; k < nl; k++ )
  180.             {
  181.                 cx[k][n] = cx[k][i] + dx[k];
  182.                 cy[k][n] = cy[k][i] + dy[k];
  183.             }
  184.  
  185.             if(!( ToFrontCount % 25 ))
  186.                 RetVal = ContinueBlanking();
  187.         }
  188.         UnblankMousePointer( Wnd );
  189.  
  190.         if( mP->Cycle == 3 )
  191.             clearCopperList( vp );
  192.     }
  193.     else
  194.         RetVal = FAILED;
  195.  
  196.     if( cx )
  197.     {
  198.         for( k = 0; k < nl; k++ )
  199.             if( cx[k] )
  200.                 FreeVec( cx[k] );
  201.         FreeVec( cx );
  202.     }
  203.  
  204.     if( cy )
  205.     {
  206.         for( k = 0; k < nl; k++ )
  207.             if( cy[k] )
  208.                 FreeVec( cy[k] );
  209.         FreeVec( cy );
  210.     }
  211.  
  212.     if( dx )
  213.         FreeVec( dx );
  214.     if( dy )
  215.         FreeVec( dy );
  216.  
  217.     if(!( mP->Cycle ))
  218.         RainbowPalette( 0L, ColorTable, 1L, 0L );
  219.     
  220.     if( MoireScr )
  221.         CloseScreen( MoireScr );
  222.  
  223.     return RetVal;
  224. }
  225.