home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / util / gblanker-38.8.lha / GBlanker / GSource / Blankers / Fractal / blank.c next >
C/C++ Source or Header  |  1994-11-05  |  2KB  |  92 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 <math.h>
  11. #include "/includes.h"
  12.  
  13. #include "Fractal_rev.h"
  14. STATIC const UBYTE VersTag[] = VERSTAG;
  15.  
  16. VOID Defaults( PrefObject *Prefs )
  17. {
  18.     Prefs[0].po_ModeID = getTopScreenMode();
  19.     Prefs[0].po_Depth = 4;
  20. }
  21.  
  22. LONG FracBlank( struct Screen *Scr, UWORD Wid, UWORD Hei )
  23. {
  24.     float x = 0, y = 0, xx, yy, a, b, c;
  25.     LONG i, xe, ye, flg_end = OK, mod = ( 1L << Scr->BitMap.Depth ) - 1;
  26.     struct RastPort *Rast = &( Scr->RastPort );
  27.     
  28.     SetRast( Rast, 0 );
  29.     ScreenToFront( Scr );
  30.     
  31.     a = (float)RangeRand( 1000 ) / 10 - 50.0;
  32.     do
  33.         b = (float)RangeRand( 1000 ) / 10 - 50.0;
  34.     while( b == 0.0 );
  35.     c = (float)RangeRand( 1000 ) / 10 - 50.0;
  36.     
  37.     for( i = 0; i < 50000 && flg_end == OK; i++ )
  38.     {
  39.         if(!( i % 50 ))
  40.         {
  41.             ScreenToFront( Scr );
  42.             flg_end = ContinueBlanking();
  43.         }
  44.         
  45.         if( x < 0 )
  46.             xx = y + sqrt( fabs( b * x - c ));
  47.         else
  48.             xx = y - sqrt( fabs( b * x - c ));
  49.         yy = a - x;
  50.         xe = Wid / 2 + (SHORT)x;
  51.         ye = Hei / 2 + (SHORT)y;
  52.         
  53.         if(( xe >= 0 )&&( ye >= 0 )&&( xe < Wid )&&( ye < Hei ))
  54.         {
  55.             SetAPen( Rast, ( ReadPixel( Rast, xe, ye ) + 1 ) % mod + 1 );
  56.             WritePixel( Rast, xe, ye );
  57.         }
  58.         
  59.         x = xx;
  60.         y = yy;
  61.     }
  62.  
  63.     return flg_end;
  64. }
  65.  
  66. LONG Blank( PrefObject *Prefs )
  67. {
  68.     struct Screen *Scr;
  69.     struct Window *Wnd;
  70.     LONG RetVal = OK;
  71.     
  72.     Scr = OpenScreenTags( 0L, SA_DisplayID, Prefs->po_ModeID, SA_Quiet, TRUE,
  73.                          SA_Depth, Prefs->po_Depth, SA_Behind, TRUE,
  74.                          SA_Overscan, OSCAN_STANDARD, TAG_DONE );
  75.     if( Scr )
  76.     {
  77.         Triplet *ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  78.         Wnd = BlankMousePointer( Scr );
  79.         
  80.         while( RetVal == OK )
  81.             RetVal = FracBlank( Scr, Scr->Width, Scr->Height );
  82.         
  83.         UnblankMousePointer( Wnd );
  84.         RainbowPalette( 0L, ColorTable, 1L, 0L );
  85.         CloseScreen( Scr );
  86.     }
  87.     else
  88.         RetVal = FAILED;
  89.  
  90.     return RetVal;
  91. }
  92.