/*

Java Graphics Demos: 

by Orion Lawlor, 12/1998

olawlor@acm.org



This code is totally free, and

should be considered in the public domain.

Use and modify it at will.

*/

//import ColorMap;

//import ByteTable;
import java.awt.*;

import java.awt.image.*;




class Demo 

{

	int w,h;

	public void init(ColorMap cm,byte pix[],int Nw,int Nh)

	{

		int x,y;

		w=Nw;h=Nh;

		for (y=0;y<h;y++)

		{

			int i=y*w;

			for (x=0;x<w;x++)

			{

				int cx1=w/2+30, cy1=h/2+80;

				int cx2=w/2-100,cy2=h/2-40;

				double r1=Math.sqrt((x-cx1)*(x-cx1)+(y-cy1)*(y-cy1));

				double r2=Math.sqrt((x-cx2)*(x-cx2)+(y-cy2)*(y-cy2));

				pix[i+x]=(byte)(128+

							30.0*Math.cos(r1/7.0)+

							50.0*Math.cos(r2/12.0));

			}

		}

	}

	public boolean handleAction(Event ev,Object obj) {return false;}

	int dex[]={0,94,170,255};

	int red[]={0,100,200,255};

	int grn[]={0,100,200,255};

	int blu[]={0,100,200,255};

	public void fillBuffer(ColorMap cm,byte pix[])

	{

		int i;

		for (i=1;i<4;i++)

		{//Note: 0xff&a == a%256.  This keeps the colors reasonable.*/

			red[i]=0xff&(int)(red[i]+(Math.random()-0.5)*20);

			grn[i]=0xff&(int)(grn[i]+(Math.random()-0.5)*20);

			blu[i]=0xff&(int)(blu[i]+(Math.random()-0.5)*20);

		}

		red[0]=red[3]; grn[0]=grn[3]; blu[0]=blu[3];

		cm.addBreaks(dex,red,grn,blu);

	}

}

