;/*
sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE RandomDots.c
slink from LIB:c.o RandomDots.o to //Clients/RandomDots LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
delete RandomDots.o
quit

 RandomDots 1.0  (Client for BServer)

 Copyright © 1995 by Stefano Reksten of 3AM - The Three Amigos!!!
 All rights reserved.
*/

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

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <clib/alib_protos.h>

#include "/include/client.h"

char *ver = "$VER: RandomDots 1.0 "__AMIGADATE__;

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct DisplayIDInformation *dinfo;

int size;

extern ULONG RangeSeed;


void Blank( void )
{
struct Screen *scr;
register UWORD swidth, sheight, cx, cy, sw, sh;

if ( scr = CloneFrontmostScreen( GETBRIGHTNESS(dinfo) ) )
	{
	register struct RastPort *rp = &(scr->RastPort);

	sw = scr->Width - 1;
	sh = scr->Height - 1;
	swidth = (sw/size) + 1;
	sheight = (sh/size) + 1;

	SpritesOff();
	SetAPen( rp, DarkestColorIndex( scr ) );

	while( STILL_BLANKING )
		{
		cx = RangeRand( swidth ) * size;
		cy = RangeRand( sheight ) * size;

		RectFill( rp, cx, cy, ((cx + size - 1) > sw ? sw : (cx + size - 1)), ((cy + size - 1) > sh ? sh : (cy + size - 1)) );
		}

	CloseScreen( scr );
	SpritesOn();
	}
else
	SendClientMsg( ACTION_FAILED );
}


void __main( void )
{
if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
	{
	if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
		{
		if ( dinfo = OpenCommunication() )
			{
			if ( (!GetArgInt( dinfo->di_Args, "SIZE", &size )) || size == 0 || size > 32 )
				size = 5;
			CurrentTime( &RangeSeed, &RangeSeed );
			Blank();
			CloseCommunication( dinfo );
			}
		CloseLibrary( (struct Library *)GfxBase );
		}
	CloseLibrary( (struct Library *)IntuitionBase );
	}
}
