#include <exec/types.h>
#include <intuition/intuition.h>
#include <dos/dos.h>

#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/alib_protos.h>

#include <math.h>

#include "/defs.h"
#include "/utility.h"

extern	ULONG	Mode;

VOID Dragon( struct Screen *Scr, SHORT Wid, SHORT Hei )
{
	SHORT	i, flg_end = FALSE;
	float	xx, yy, x = 0, y = 0;
	float	t = (float)( RangeRand( 100 ) + 10 ), a = M_PI - t / 5000;

	SetRGB4(&( Scr->ViewPort ), 1, RangeRand( 14 ) + 1, RangeRand( 14 ) + 1, RangeRand( 14 ) + 1 );
	SetRast(&( Scr->RastPort ), 0 );
	ScreenToFront( Scr );

	for( i = 0; i < 40000 && !flg_end; i++ ) {
		if(!( i % 100 )) flg_end = SetSignal( 0L ,0L ) & SIGBREAKF_CTRL_C;

		xx = y - sin( x );
		yy = a - x;

		WritePixel(&( Scr->RastPort ), Wid / 2 + (SHORT)( 2.0 * x ), Hei / 2 + (SHORT)( 2.0 * y ));

		x = xx;
		y = yy;
	}
}

VOID blank( VOID )
{
	struct Screen *Scr;

	if( Scr = OpenScreenTags( NULL, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD, SA_DisplayID, Mode, SA_Quiet,
		TRUE, SA_Behind, TRUE, TAG_DONE )) {

		SetRGB4(&( Scr->ViewPort ), 0, 0, 0, 0 );
		BlankMousePointer();

		while(!( SetSignal( 0L ,0L ) & SIGBREAKF_CTRL_C )) Dragon( Scr, Scr->Width, Scr->Height );

		SetSignal( 0L, SIGBREAKF_CTRL_C );
		UnblankMousePointer();
		CloseScreen( Scr );
	}
}
