// MiddleGrid.tra
// Author - MrC
// Based on FadeMiddleGrid.r4 By Gordon Williams

int x,y,mx,my,hx,hy;
float dx,dy,sx,sy,a,b,mytime;

void Init()
{

}

void Render()
{
	mytime = mytime + (TIMEPASS*0.40);


	gfxSetAspect(0);
	gfxTranslate(-1, -1, 2.414);
	gfxSetTexture(TEXTURE_NEXTPRESET);
	gfxColour(1, 1, 1, 1);
	gfxTexRect(0, 2, 2, 0);

	mx = 16;
	my = 12;
	hx = 8;
	hy = 6;

	gfxScale(2.0/mx,2.0/my,1.0);
	sx = 1.0/mx;
	sy = 1.0/my;

	gfxSetTexture(TEXTURE_CURRPRESET);
	gfxColour(1, 1, 1, 1);

	gfxBegin(PRIM_QUADLIST);

	FINISHED = true;

	dx = 0;
	for (x=0;x<mx;x=x+1)
	{
		dy = 0;
		for (y=0;y<my;y=y+1)
		{     
			a = (mytime*10.0)-((Abs(x-hx)+Abs(y-hy))*0.25);
			if (a<0) a=0;
			if (a<3.14159)
			{
				a = (Cos(a)*0.25)+0.25;
				gfxTexCoord(dx,1.0f - dy);
				gfxVertex(x+0.5-a,y+0.5-a,0.0);
				gfxTexCoord(dx+sx,1.0f-dy);
				gfxVertex(x+0.5+a,y+0.5-a,0.0);
				gfxTexCoord(dx+sx,1.0f-(dy+sy));
				gfxVertex(x+0.5+a,y+0.5+a,0.0);
				gfxTexCoord(dx,1.0f - (dy+sy));
				gfxVertex(x+0.5-a,y+0.5+a,0.0);
				FINISHED = false;
			}
			dy = dy + sy;
		}
		dx = dx + sx;
	}
	gfxEnd();

}
