home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / plasma / blank.c next >
C/C++ Source or Header  |  1994-10-17  |  4KB  |  203 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/types.h>
  10. #include <exec/memory.h>
  11.  
  12. #include <intuition/intuition.h>
  13. #include <dos/dos.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/intuition_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <clib/alib_protos.h>
  19.  
  20. #include "/Garshnelib/Garshnelib_protos.h"
  21. #include "/Garshnelib/Garshnelib_pragmas.h"
  22.  
  23. #include "Plasma.h"
  24. #include "/main.h"
  25. #include "//defs.h"
  26.  
  27. struct ModulePrefs
  28. {
  29.     LONG Mode;
  30.     LONG Depth;
  31.     LONG LimDimen;
  32.     LONG ExtendPal;
  33. };
  34.  
  35. extern struct ModulePrefs nP;
  36. LONG Range[] = { 63, 31, 15, 7, 7, 3, 2, 2 }, Hei, Wid, Minor, Offx, Offy;
  37. LONG **Cell, Cl, Dimen;
  38. Triplet *ColorTable = 0L;
  39.  
  40. void set( LONG l, LONG c, LONG size, LONG value, struct RastPort *R )
  41. {
  42.     LONG rang;
  43.     
  44.     rang = Range[size];
  45.     value = ( value + RangeRand( rang ) - ( rang + 1 ) / 2 ) % Cl;
  46.     Cell[c][l] = value;
  47.     if( value )
  48.         SetAPen( R, value );
  49.     else
  50.         SetAPen( R, 1 );
  51.     if(( l < Hei )&&( c < Wid ))
  52.         WritePixel( R, c + Offx, l + Offy );
  53. }
  54.  
  55. LONG grow( struct Screen *Scr, LONG ExtendPal )
  56. {
  57.     LONG l, c, i, z = 0, step, nextStep, l1, l2, c1, c2, RetVal = OK;
  58.     struct RastPort *R = &( Scr->RastPort );
  59.     
  60.     step = 256;
  61.     for( i = 0; i < 8; i++ )
  62.     {
  63.         nextStep = step / 2;
  64.         for( l = 0; ( l < Minor )&&( RetVal == OK ); l += step )
  65.         {
  66.             l1 = ( l + nextStep ) % Minor;
  67.             l2 = ( l + step ) % Minor;
  68.             for( c = 0; c < Minor; c += step )
  69.             {
  70.                 c1 = ( c + nextStep ) % Minor;
  71.                 c2 = ( c + step ) % Minor;
  72.                 set( l, c1, i, ( Cell[l][c] + Cell[l][c2] + 1 )/2, R );
  73.                 set( l1, c, i, ( Cell[l][c] + Cell[l2][c] + 1 )/2, R );
  74.                 set( l1, c1, i, ( Cell[l][c] + Cell[l][c2] + Cell[l2][c] +
  75.                                  Cell[l2][c2] + 2 )/4, R );
  76.             }
  77.             if(!( ++z % 4 ))
  78.             {
  79.                 RainbowPalette( Scr, ColorTable, 1, ExtendPal );
  80.                 RetVal = ContinueBlanking();
  81.             }
  82.         }
  83.         step = nextStep;
  84.     }
  85.  
  86.     return RetVal;
  87. }
  88.  
  89. LONG **FreeCells( LONG **Cells )
  90. {
  91.     LONG i;
  92.     
  93.     if( Cells )
  94.         for( i = 0; i < Minor; i++ )
  95.             if( Cells[i] )
  96.                 FreeVec( Cells[i] );
  97.     
  98.     return 0L;
  99. }
  100.  
  101. LONG **AllocCells( LONG InitColor )
  102. {
  103.     LONG i, j, failed = 0;
  104.     LONG **Cell;
  105.     
  106.     if( Cell = AllocVec( Minor * sizeof( LONG * ), MEMF_CLEAR ))
  107.     {
  108.         for( i = 0; i < Minor; i ++ )
  109.         {
  110.             if(!( Cell[i] = AllocVec( Minor * sizeof( LONG ), MEMF_CLEAR )))
  111.                 failed = 1;
  112.             else
  113.                 for( j = 0; j < Minor; j++ )
  114.                     Cell[i][j] = InitColor;
  115.         }
  116.     }
  117.  
  118.     if( !failed )
  119.         return Cell;
  120.  
  121.     return FreeCells( Cell );
  122. }
  123.  
  124. LONG Blank( VOID *Prefs )
  125. {
  126.     struct ModulePrefs *pP;
  127.     struct Screen *Scr;
  128.     struct Window *Wnd;
  129.     LONG i, RetVal = OK;
  130.     
  131.     if( PlasmaWnd )
  132.         pP = &nP;
  133.     else
  134.         pP = ( struct ModulePrefs * )Prefs;
  135.  
  136.     Scr = OpenScreenTags( NULL, SA_Depth, pP->Depth,SA_DisplayID, pP->Mode,
  137.                          SA_Overscan, OSCAN_STANDARD, SA_Quiet, TRUE,
  138.                          SA_Behind, TRUE, TAG_DONE );
  139.     if( Scr )
  140.     {
  141.         Cl = 1L << pP->Depth - 1;
  142.         Wid = Scr->Width;
  143.         Hei = Scr->Height;
  144.  
  145.         if( pP->LimDimen )
  146.         {
  147.             Minor = Hei;
  148.             if( Wid > Hei )
  149.                 Offx = ( Wid - Hei )/ 2;
  150.             else
  151.                 Offx = 0L;
  152.             Offy = 0L;
  153.         }
  154.         else
  155.         {
  156.             Minor = Wid;
  157.             Offx = 0L;
  158.             if( Hei > Wid )
  159.                 Offy = ( Hei - Wid )/ 2;
  160.             else
  161.                 Offy = 0;
  162.         }
  163.         
  164.         Cell = AllocCells(( LONG )RangeRand( 256 ));
  165.  
  166.         if( Cell )
  167.         {
  168.             ColorTable = RainbowPalette( Scr, 0L, 1, pP->ExtendPal );
  169.             Wnd = BlankMousePointer( Scr );
  170.             
  171.             while( RetVal == OK )
  172.             {
  173.                 ScreenToFront( Scr );
  174.                 SetRast(&( Scr->RastPort ), 0L );
  175.                 RetVal = grow( Scr, pP->ExtendPal );
  176.                 
  177.                 for( i = 0; ( i < Wid * Hei / 100 )&&( RetVal == OK ); i++ )
  178.                 {
  179.                     WaitTOF();
  180.                     if(!( i % 4 ))
  181.                     {
  182.                         RainbowPalette( Scr, ColorTable, 1, pP->ExtendPal );
  183.                         RetVal = ContinueBlanking();
  184.                     }
  185.                 }
  186.             }
  187.             
  188.             RainbowPalette( NULL, ColorTable, 1, pP->ExtendPal );
  189.             UnblankMousePointer( Wnd );
  190.  
  191.             FreeCells( Cell );
  192.         }
  193.         else
  194.             RetVal = FAILED;
  195.  
  196.         CloseScreen( Scr );
  197.     }
  198.     else
  199.         RetVal = FAILED;
  200.     
  201.     return RetVal;
  202. }
  203.