home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / interference / blank.c next >
C/C++ Source or Header  |  1994-10-08  |  3KB  |  116 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 <intuition/intuition.h>
  11. #include <dos/dos.h>
  12.  
  13. #include <clib/exec_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 "Interference.h"
  22. #include "//defs.h"
  23. #include "/main.h"
  24.  
  25. struct ModulePrefs
  26. {
  27.     LONG Mode;
  28.     LONG Depth;
  29.     LONG ExtendPal;
  30. };
  31.  
  32. extern struct ModulePrefs nP;
  33.  
  34. LONG ExtendPal;
  35. Triplet *ColorTable = 0L;
  36.  
  37. LONG Interference( struct Screen *Scr )
  38. {
  39.     LONG Wid = Scr->Width, Hei = Scr->Height, RetVal = OK, Pixel = 0, x, y;
  40.     LONG factor, Colors = ( 1L << Scr->BitMap.Depth ) - 1;
  41.     LONG Transition =  Colors * 2 - 1, PixelVal;
  42.     struct RastPort *R = &( Scr->RastPort );
  43.  
  44.     ScreenToFront( Scr );
  45.  
  46.     factor = RangeRand( 20 ) + 1;
  47.     for( y = -Hei / 2 + 1; y <= 0 && RetVal == OK; y++ )
  48.     {
  49.         for( x = -Wid / 2 + 1; x <= 0; x++ )
  50.         {
  51.             PixelVal =  (( x * x + y * y ) / factor ) % Transition;
  52.             if( PixelVal >= Colors )
  53.                 PixelVal = Transition - PixelVal;
  54.             
  55.             SetAPen( R, PixelVal + 1 );
  56.             WritePixel( R, Wid / 2 - 1 + x, Hei / 2 - 1 + y );
  57.             WritePixel( R, Wid / 2 - 1 - x, Hei / 2 - 1 + y );
  58.             WritePixel( R, Wid / 2 - 1 + x, Hei / 2 - 1 - y );
  59.             WritePixel( R, Wid / 2 - 1 - x, Hei / 2 - 1 - y );
  60.             if(!( ++Pixel % 600 ))
  61.                 RetVal = ContinueBlanking();
  62.         }
  63.         RainbowPalette( Scr, ColorTable, 1L, ExtendPal );
  64.         WaitTOF();
  65.     }
  66.  
  67.     for( x = 0; x < 400 && RetVal == OK; x++ )
  68.     {
  69.         WaitTOF();
  70.         if(!( x % 4 ))
  71.         {
  72.             RainbowPalette( Scr, ColorTable, 1L, ExtendPal );
  73.             RetVal = ContinueBlanking();
  74.         }
  75.     }
  76.  
  77.     return RetVal;
  78. }
  79.  
  80. LONG Blank( VOID *Prefs )
  81. {
  82.     struct Screen *Scr;
  83.     struct Window *Wnd;
  84.     struct ModulePrefs *mP;
  85.     LONG RetVal = OK;
  86.     
  87.     if( InterferenceWnd )
  88.         mP = &nP;
  89.     else
  90.         mP = ( struct ModulePrefs * )Prefs;
  91.  
  92.     Scr = OpenScreenTags( 0L, SA_Depth, mP->Depth, SA_Overscan, OSCAN_STANDARD,
  93.                          SA_DisplayID, mP->Mode, SA_Quiet, TRUE,
  94.                          SA_Behind, TRUE, TAG_DONE );
  95.     
  96.     if( Scr )
  97.     {
  98.         SetRast(&( Scr->RastPort ), 0 );
  99.         ColorTable = RainbowPalette( Scr, 0L, 1L, ExtendPal = mP->ExtendPal );
  100.         Wnd = BlankMousePointer( Scr );
  101.  
  102.         ScreenToFront( Scr );
  103.  
  104.         while( RetVal == OK )
  105.             RetVal = Interference( Scr );
  106.  
  107.         UnblankMousePointer( Wnd );
  108.         RainbowPalette( NULL, ColorTable, 1L, ExtendPal );
  109.         CloseScreen( Scr );
  110.     }
  111.     else
  112.         RetVal = FAILED;
  113.  
  114.     return RetVal;
  115. }
  116.