home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 105
/
af105sub.adf
/
Beyondthedark.LZX
/
BeyondTheDark
/
Developer
/
Source
/
Interference
/
Interference.c
next >
Wrap
C/C++ Source or Header
|
2013-06-15
|
9KB
|
367 lines
/* Interference Library */
#include <exec/memory.h>
#include <exec/execbase.h>
#include <graphics/gfxbase.h>
#include <intuition/intuitionbase.h>
#include <libraries/iffparse.h>
#include <utility/tagitem.h>
#include <clib/macros.h>
#define __USE_SYSBASE 42
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/mathieeedoubbas.h>
#include <proto/mathieeedoubtrans.h>
#include <proto/utility.h>
#include <math.h>
#include <BTD.h>
struct IntuitionBase *IntuitionBase;
struct Library *UtilityBase;
struct GfxBase *GfxBase;
struct Library *MathIeeeDoubBasBase;
struct Library *MathIeeeDoubTransBase;
#define KTAG(o) (BTD_Client+(o))
#define IS_Colors KTAG(0)
#define IS_Cycle KTAG(1)
#define IS_Cycling KTAG(2)
#define IS_Formula KTAG(3)
#define IS_Clear KTAG(4)
#define MAX_CYCLING 1000L
#define DEF_CYCLING 60L
#define MAX_COLORS 255
#define DEF_COLORS 31
#define MAX_FORMULA 1
#define DEF_FORMULA 0
#define FindTagData(l,t,d) GetTagData((t),(d),(l))
char *Formulas[] = {"Quadratic","Cubic",NULL};
struct BTDCycle InterferenceCycleParams[] =
{
IS_Formula,"Formula",BTDPT_CYCLE,DEF_FORMULA,Formulas
};
struct BTDInteger InterferenceIntParams[] =
{
IS_Cycling,"Cycling Counter",BTDPT_INTEGER,DEF_CYCLING,1L,MAX_CYCLING,TRUE,
IS_Colors,"Colors",BTDPT_INTEGER,DEF_COLORS,2L,MAX_COLORS,TRUE
};
struct BTDBoolean InterferenceBoolParams[] =
{
IS_Cycle,"Cycle",BTDPT_BOOLEAN,TRUE,
IS_Clear,"Clear before redraw",BTDPT_BOOLEAN,FALSE
};
struct BTDNode *InterferenceParams[] =
{
&InterferenceCycleParams[0].BC_Node,
&InterferenceIntParams[1].BI_Node,
&InterferenceBoolParams[0].BB_Node,
&InterferenceIntParams[0].BI_Node,
&InterferenceBoolParams[1].BB_Node,
NULL
};
struct BTDInfo InterferenceInfo =
{
BTDI_Revision,MAKE_ID('I','F','R','C'),
"Interference Blanker","selfmade blanker\nbased on some fractal exposées","Markus Illenseer '92,'93,'94",
InterferenceParams};
struct InterferenceStruct
{
struct BTDDrawInfo *BTDDrawInfo;
UWORD Seconds;
UWORD Time;
UWORD Left; /* Left Offset of our Rect */
UWORD Top; /* Top Offset of our Rect */
UWORD Width; /* Width of our Rect */
UWORD Height; /* Height of our Rect */
DOUBLE str,sti;
UWORD ypos;
UWORD xpos;
BOOL DoCycle;
UWORD Formula;
LONG hs_RandN,hs_RandF,hs_RandI;
SHORT Cycle;
SHORT Colors;
SHORT Cycling;
BOOL Clear;
};
/* library stuff */
char MyBlankerName[] = "interference.btd";
char MyBlankerID[] = "Interference Blanker V" VERSION "." REVISION " for BTD";
LONG MyBlankerLibInit(void)
{
if (GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37L))
{
if (IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L))
{
if (UtilityBase=OpenLibrary("utility.library",37L))
{
if (MathIeeeDoubBasBase=OpenLibrary("mathieeedoubbas.library",37L))
{
if (MathIeeeDoubTransBase=OpenLibrary("mathieeedoubtrans.library",37L)) return TRUE;
CloseLibrary (MathIeeeDoubBasBase);
}
CloseLibrary (UtilityBase);
}
CloseLibrary (&IntuitionBase->LibNode);
}
CloseLibrary (&GfxBase->LibNode);
}
return FALSE;
}
void MyBlankerLibFree(void)
{
CloseLibrary (MathIeeeDoubTransBase);
CloseLibrary (MathIeeeDoubBasBase);
CloseLibrary (UtilityBase);
CloseLibrary (&IntuitionBase->LibNode);
CloseLibrary (&GfxBase->LibNode);
}
struct BTDInfo *QueryMyBlanker(void)
{
return &InterferenceInfo;
}
void __regargs InitRandom(struct InterferenceStruct *IS,ULONG Instance)
{
ULONG Time[2];
CurrentTime (&Time[0],&Time[1]);
IS->hs_RandN=(LONG)Time[0];
if (Time[1]<1024L) Time[1]|=1;
else Time[1]>>=10;
Time[1]^=Instance;
IS->hs_RandF=4*Time[1]+1;
IS->hs_RandI=2*Time[1]+1;
}
WORD __regargs Random(struct InterferenceStruct *IS,WORD Max)
{
IS->hs_RandN=IS->hs_RandF*IS->hs_RandN+IS->hs_RandI;
if (IS->hs_RandN<0L) IS->hs_RandN=-IS->hs_RandN;
return (WORD)(IS->hs_RandN%Max);
}
struct InterferenceStruct *InitMyBlanker(struct TagItem *TagList)
{
struct BTDDrawInfo *BTDDrawInfo;
struct InterferenceStruct *IS;
ULONG *Error,Dummy;
UWORD Index,Instance,Formula;
LONG Colors,Step,Cycling;
BOOL DoCycle,Clear;
if ((BTDDrawInfo=(struct BTDDrawInfo *)
FindTagData(TagList,BTD_DrawInfo,NULL))==NULL) return NULL;
Error=(LONG *)FindTagData(TagList,BTD_Error,(ULONG)&Dummy);
if ((IS=AllocVec(sizeof(struct InterferenceStruct),MEMF_PUBLIC|MEMF_CLEAR))==NULL)
{
*Error=BTDERR_Memory;
return NULL;
}
Instance=FindTagData(TagList,BTD_Instance,0L);
Colors=FindTagData(TagList,IS_Colors,DEF_COLORS);
Cycling=FindTagData(TagList,IS_Cycling,DEF_CYCLING);
DoCycle=FindTagData(TagList,IS_Cycle,TRUE);
Clear=FindTagData(TagList,IS_Clear,FALSE);
Formula=FindTagData(TagList,IS_Formula,DEF_FORMULA);
InitRandom(IS,Instance);
IS->BTDDrawInfo=BTDDrawInfo;
IS->Left=IS->BTDDrawInfo->BDI_Left;
IS->Top=IS->BTDDrawInfo->BDI_Top;
IS->Width=IS->BTDDrawInfo->BDI_Width;
IS->Height=IS->BTDDrawInfo->BDI_Height;
IS->ypos=IS->Top;
IS->xpos=IS->Left;
IS->str=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(IS->Width));
IS->sti=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(IS->Height));
IS->Formula = Formula;
IS->Cycle=0;
IS->DoCycle=DoCycle;
IS->Cycling=Cycling;
IS->Clear=Clear;
IS->Colors=Colors-1;
Step=(256/(IS->Colors));
for(Index=0; Index<IS->Colors+1; Index++)
{
BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[Index]]=Step*(Index);
BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[Index]]=0;
BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[Index]]=255-Step*(Index);
BTDDrawInfo->BDI_Changed[BTDDrawInfo->BDI_Pens[Index]]=TRUE;
}
return IS;
}
void EndMyBlanker(struct InterferenceStruct *IS)
{
FreeVec (IS);
}
void AnimMyBlanker(struct InterferenceStruct *IS)
{
DOUBLE I,R;
static UWORD X,Y,Z,H,T,L,W;
struct BTDDrawInfo *BTDDrawInfo;
BTDDrawInfo=IS->BTDDrawInfo;
IS->xpos++;
X=IS->xpos;
L=IS->Left;
W=IS->Width;
if(X>L+W)
{
IS->xpos=X=L;
IS->ypos++;
}
Y=IS->ypos;
H=IS->Height;
T=IS->Top;
if (Y>=(H+T))
{
UBYTE Red,Green,Blue;
ULONG Index;
if(IS->DoCycle)
{
if(IS->Cycle<=0) IS->Cycle=IS->Cycling;
if(IS->Cycle>=2)
{
IS->Cycle--;
for (Index=0L; Index<7L; Index++)
WaitTOF();
Red=BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[0]];
Green=BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[0]];
Blue=BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[0]];
for (Index=0L; Index<IS->Colors; Index++)
{
BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[Index]]=
BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[Index+1]];
BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[Index]]=
BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[Index+1]];
BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[Index]]=
BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[Index+1]];
}
for (Index=0L; Index<IS->Colors; Index++)
BTDDrawInfo->BDI_Changed[BTDDrawInfo->BDI_Pens[Index]]=TRUE;
BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[Index]]=Red;
BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[Index]]=Green;
BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[Index]]=Blue;
BTDDrawInfo->BDI_Changed[BTDDrawInfo->BDI_Pens[Index]]=TRUE;
}
}
else
{
/* Dammit, muss das doppelt gemacht werden.. grummel */
IS->str=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(W));
IS->sti=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(H));
if(IS->Clear)
{
SetAPen (BTDDrawInfo->BDI_RPort,BTD_BgPen);
RectFill (BTDDrawInfo->BDI_RPort,L,T,
W-1,T+H-1);
}
IS->ypos=T;
IS->xpos=L;
}
if(IS->Cycle==1)
{
IS->str=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(W));
IS->sti=IEEEDPDiv(IEEEDPFlt(Random(IS,80)+20),IEEEDPFlt(H));
if(IS->Clear)
{
SetAPen (BTDDrawInfo->BDI_RPort,BTD_BgPen);
RectFill (BTDDrawInfo->BDI_RPort,L,T,
L+W-1,T+H-1);
}
IS->ypos=T;
IS->xpos=L;
IS->Cycle=0;
}
}
else
{
I=IEEEDPMul(IEEEDPFlt(Y),IS->sti);
{
R=IEEEDPMul(IEEEDPFlt(X),IS->str);
if(IS->Formula==0)
Z=IEEEDPFix(IEEEDPAdd(IEEEDPMul(R,R),IEEEDPMul(I,I)));
/* i^2,r^2 */
else
Z=IEEEDPFix(IEEEDPAdd(IEEEDPMul(R,IEEEDPMul(R,R)),IEEEDPMul(I,IEEEDPMul(I,I))));
/* i^3,r^3 */
SetAPen (BTDDrawInfo->BDI_RPort,BTDDrawInfo->BDI_Pens[(Z%(IS->Colors))]);
WritePixel (BTDDrawInfo->BDI_RPort,X,Y);
}
}
}
ULONG PenCountMyBlanker(struct TagItem *TagList)
{
return FindTagData(TagList,IS_Colors,DEF_COLORS);
}