home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / util / gblanker-38.8.lha / GBlanker / GSource / Blankers / Lightning / blank.c next >
C/C++ Source or Header  |  1994-11-05  |  4KB  |  195 lines

  1. /*
  2.  **    SPHINX-O-Lightning
  3.  **    a module for Garshneblanker
  4.  **
  5.  **    Copyright (C) 1993 SPHINX.
  6.  **    Programmed by Raymond Penners.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include "/includes.h"
  13.  
  14. UWORD ColorsOn[] = { 0x000, 0xFFF, 0xAAA, 0x444 };
  15. #define PaletteOn( V ) LoadRGB4( V, ColorsOn, 4 )
  16.  
  17. UWORD ColorsOff[] = { 0, 0, 0, 0 };
  18. #define PaletteOff( V ) LoadRGB4( V, ColorsOff, 4 )
  19.  
  20. UWORD Width, Height, Forkiness;
  21.  
  22. #include "Lightning_rev.h"
  23. STATIC const UBYTE VersTag[] = VERSTAG;
  24.  
  25. VOID Defaults( PrefObject *Prefs )
  26. {
  27.     Prefs[0].po_Level = 6;
  28.     Prefs[2].po_Level = 4;
  29.     Prefs[4].po_ModeID = getTopScreenMode();
  30. }
  31.  
  32. VOID DrawLine( struct RastPort *Rast, SHORT x1, SHORT y1, SHORT x2, SHORT y2,
  33.               SHORT col )
  34. {
  35.     if( x1 < 0 )
  36.     {
  37.         if( x2 < 0 )
  38.             return;
  39.         x1 = 0;
  40.     }
  41.     else if( x1 >= Width )
  42.     {
  43.         if( x2 >= Width )
  44.             return;
  45.         x1 = Width - 1;
  46.     }
  47.     
  48.     if( y1 < 0 )
  49.     {
  50.         if( y2 < 0 )
  51.             return;
  52.         y1 = 0;
  53.     }
  54.     else if( y1 >= Height )
  55.     {
  56.         if( y2 >= Height )
  57.             return;
  58.         y1 = Height - 1;
  59.     }
  60.  
  61.     if( x2 < 0 )
  62.         x2 = 0;
  63.     else if( x2 >= Width )
  64.         x2 = Width - 1;
  65.     
  66.     if( y2 < 0 )
  67.         y2 = 0;
  68.     else if( y2 >= Height )
  69.         y2 = Height - 1;
  70.     
  71.     SetAPen( Rast, col );
  72.     Move( Rast, x1, y1 );
  73.     Draw( Rast, x2, y2 );
  74. }
  75.  
  76. VOID DrawLightning( struct RastPort *Rast, LONG X, LONG Y, LONG Segments,
  77.                    double Dir, LONG Fork )
  78. {
  79.     double Sign = PI/8, xSeg, ySeg;
  80.     LONG nX, nY;
  81.  
  82.     xSeg = ( double )( Width / ( 15 * Fork ));
  83.     ySeg = ( double )( Height / ( 15 * Fork ));
  84.  
  85.     while( --Segments &&( Y < Height ))
  86.     {
  87.         LONG Angle = RangeRand( 100 );
  88.         double DeltaAngle = Sign * ( double )Angle / 100.0;
  89.         
  90.         Dir = Dir + DeltaAngle;
  91.         Sign = Sign * -1.0;
  92.         
  93.         nX = X + ( LONG )( cos( Dir ) * xSeg );
  94.         nY = Y + ( LONG )( sin( Dir ) * ySeg );
  95.  
  96.         DrawLine( Rast, X, Y, nX, nY, Fork );
  97.  
  98.         X = nX;
  99.         Y = nY;
  100.  
  101.         if(( Fork < 3 )&&( RangeRand( 50 ) < ( Forkiness / Fork )))
  102.             DrawLightning( Rast, X, Y, 5 + RangeRand( 10 ),
  103.                           Dir - 2.0 * DeltaAngle, Fork + 1 );
  104.     }
  105. }
  106.  
  107. LONG Pause( LONG Ticks )
  108. {
  109.     LONG RetVal = ContinueBlanking();
  110.  
  111.     while( RetVal == OK && ( Ticks -= 2 ) > 0 )
  112.     {
  113.         Delay( 2 );
  114.         RetVal = ContinueBlanking();
  115.     }
  116.  
  117.     return RetVal;
  118. }
  119.  
  120. LONG Blank( PrefObject *Prefs )
  121. {
  122.     LONG ToFrontCount = 0, RetVal, Freq, i;
  123.     struct RastPort *Rast;
  124.     struct ViewPort *View;
  125.     struct Screen *Scr;
  126.     struct Window *Wnd;
  127.     
  128.     Scr = OpenScreenTags( 0L, SA_DisplayID, Prefs[4].po_ModeID, SA_Depth, 2,
  129.                          SA_Quiet, TRUE, SA_Behind, TRUE,
  130.                          SA_Overscan, OSCAN_STANDARD, TAG_DONE );
  131.     if( Scr )
  132.     {
  133.         Forkiness = Prefs[0].po_Level;
  134.         Freq = Prefs[2].po_Level;
  135.         
  136.         Rast = &Scr->RastPort;
  137.         View = &Scr->ViewPort;
  138.         Width = Scr->Width;
  139.         Height = Scr->Height;
  140.         
  141.         SetDrMd( Rast, JAM1 );
  142.         Wnd = BlankMousePointer( Scr );
  143.         
  144.         PaletteOff( View );
  145.  
  146.         do
  147.         {
  148.             Move( Rast, 0, 0 );
  149.             SetRast( Rast, 0 );
  150.             if( RangeRand( 100 ) > 50 )
  151.                 DrawLightning( Rast, RangeRand( Width/2 ), 0, 50, PI/4, 1 );
  152.             else
  153.                 DrawLightning( Rast, Width/2 + RangeRand( Width/2-1 ), 0,
  154.                               50, 3*PI/4, 1 );
  155.             
  156.             if(!( ToFrontCount++ % 25 ))
  157.                 ScreenToFront( Scr );
  158.  
  159.             i = RangeRand( 100 );
  160.             if( i < 25 )
  161.             {
  162.                 int j = 2;
  163.                 
  164.                 j += i & 1;
  165.                 while( j-- > 0 )
  166.                 {
  167.                     WaitTOF();
  168.                     PaletteOn( View );
  169.                     Delay( 1 );
  170.                     WaitTOF();
  171.                     PaletteOff( View );
  172.                 }
  173.             }
  174.             else
  175.             {
  176.                 PaletteOn( View );
  177.                 Delay( 5 );
  178.                 WaitTOF();
  179.                 PaletteOff( View );
  180.             }
  181.             
  182.             RetVal = Pause( 10 * ( 20 - Freq - RangeRand( 4 )));
  183.         }
  184.         while( RetVal == OK );
  185.         
  186.         UnblankMousePointer( Wnd );
  187.         
  188.         CloseScreen( Scr );
  189.     }
  190.     else
  191.         RetVal = FAILED;
  192.     
  193.     return RetVal;
  194. }
  195.