 /* Fichier star.dark.c				*/
/* Module appele par le programme principal	*/
/* pour effectuer un effet defini..appele par	*/
/* loadseg					*/

#include <time.h>
#include <math.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/displayinfo.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include "/includes/struct.h"
#include "/includes/tom_gadget.h"

char	p_ver[]="$VER: Line2 v1.1 (28/02/93)";

char	*p_text_info="   Effect line\n\nJust show you lines moving\non your screen...\nYou can choose to add\nhorizontal or vertical\nsymetry\nV1.1 By Thomas Landspurg\n";

struct	RastPort	*rp;
struct	Screen	*s;

#define	WIDTH	320
#define	HEIGHT	256

#define	MAX_SPEED	20
#define	MAX_NB	100

UWORD  ScreenColors[] = {
    0x000,
    0xF00,
    0xF30,
    0xF50,
    0xF70,
    0xF90,
    0xFA0,
    0xFB0,
    0xFC0,
    0xFD0,
    0xFE0,
    0xFF0,
    0xBF0,
    0x8F0,
    0x7D0,
    0x5B0,
    0x000,
    0x490,
    0x340,
    0x555,
    0x777,
    0x999,
    0xBBB,
    0xDDD,
    0xEEE,
    0xFFF,
    0xFCC,
    0xFAA,
    0xF88,
    0xF66,
    0xF44,
    0xF22,
    0x000 };

struct NewScreen   Screen = {
    0, 0, WIDTH,HEIGHT, 5,0,1,NULL,CUSTOMSCREEN,NULL,NULL,NULL,NULL};

struct tom_gadget my_gadg[]={
	{"T_aille",SLIDER,	101,15,135,9,10, 10,MAX_NB-1,0,0},
	{"_Speed",SLIDER,	101,28,135,9,10, 10,MAX_SPEED,0,0},
	{"_Horizontal",CHECKBOX,272,39,135,9,0, 0,0,0,0},
	{"_Vertical",CHECKBOX,	272,53,135,9,0, 0,0,0,0},
		{0,		END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
};

typedef	struct	pt{
	int	x,y;
	int	x2,y2;
};
struct	pt	tab_pt[MAX_NB];
extern	struct	GfxBase	*GfxBase;

void	Aff_line(rp,n)
struct	RastPort	*rp;
int	n;
{
	Move(rp,160+tab_pt[n].x,128+tab_pt[n].y);
	Draw(rp,160+tab_pt[n].x2,128+tab_pt[n].y2);

	if(my_gadg[3].value){
		Move(rp,160-tab_pt[n].x,128+tab_pt[n].y);
		Draw(rp,160-tab_pt[n].x2,128+tab_pt[n].y2);
		if(my_gadg[2].value){
			Move(rp,160-tab_pt[n].x,128-tab_pt[n].y);
			Draw(rp,160-tab_pt[n].x2,128-tab_pt[n].y2);
		}
	}
	if(my_gadg[2].value){
		Move(rp,160+tab_pt[n].x,128-tab_pt[n].y);
		Draw(rp,160+tab_pt[n].x2,128-tab_pt[n].y2);
	}
}

void	dark()
{
    int	d,i,n;

    if ( s = OpenScreen(&Screen)){

	FreeSprite (0);
	GfxBase->SpriteReserved|=1;
	rp = &(s->RastPort);
	d=1<<(s->BitMap.Depth);
	LoadRGB4(&s->ViewPort,ScreenColors,32);
	SetRast(rp,0);

	for(n=0;n<my_gadg[0].value;n++){
		tab_pt[n].x=0;
		tab_pt[n].y=0;
		tab_pt[n].x2=0;
		tab_pt[n].y2=0;
	}
	n=0;
	i=n;

	while(tst_end()==FALSE){
		i=(i+my_gadg[1].value)%6400;
		SetAPen(rp,0);
		Aff_line(rp,n);

		tab_pt[n].x=(int)(159*sin(2*i*2*PI/6400));
		tab_pt[n].y=(int)(127*cos(3*i*2*PI/6400));
		tab_pt[n].x2=(int)(120*sin(5*i*2*PI/6400));
		tab_pt[n].y2=(int)(108*cos(7*i*2*PI/6400));

		SetAPen(rp,(i/my_gadg[1].value)%31+1);
		Aff_line(rp,n);

		n=(n+1)%my_gadg[0].value;
	
	}
   CloseScreen(s);
   }

}

void	proc_init()
{
}
void	proc_save()
{
}
void	proc_end()
{
}

