/** Line Drawing Demonstrations
*/


import java.awt.*;
import Raster;
import javax.swing.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.event.*;



public class Exo4 extends JPanel  {	

	Exo4()	{	


	//  -----	Frame and Panel things
	
		setBackground(Color.blue);
        ApplicationFrame frame = new ApplicationFrame("Line Drawing Show");
        
		width = frame.getWidth();
		height = frame.getHeight();
				
		GraphicsEnvironment local = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice screen = local.getDefaultScreenDevice();
		GraphicsConfiguration configuration = screen.getDefaultConfiguration();
		

 	//	bufImg = configuration.createCompatibleImage(width, height-22);
 		bufImg = new BufferedImage(width, height-22, BufferedImage.TYPE_INT_RGB);
		gb = bufImg.createGraphics();
		
		setSize(width, height-22);
		
		double 	radius1 = height/3;
		double 	radius2 = height/4;
		double  center1x = width/4;
		double  center1y = height/2;
		double	center2x = width*5/5;
		double	center2y = height*2/3;
		double 	step1 = Math.PI/350;
		double 	step2 = Math.PI/260;
		int 	r1,g1,b1,r2,g2,b2;
		Point2D.Double	P1,P2;
		P1 = new Point2D.Double();
		P2 = new Point2D.Double();
		double	inc1,inc2;
		Color	color= new Color(0,0,0);
		
		for (inc1=0, inc2=Math.PI/2;inc1<2*Math.PI;inc1 +=step1, inc2 += step2) {
			P1.setLocation(center1x+radius1*Math.cos(inc1), center1y+1.5*radius1*Math.sin(inc1));
			P2.setLocation(center2x+radius2*Math.cos(inc2), center1y+radius1*Math.sin(inc2));
			r1 = (int)(inc1*255/(2*Math.PI));
			g1 = (int)(Math.abs(255*Math.cos(inc1)));
			b1 = (int)(Math.abs(255*Math.cos(inc2)));
//			System.out.println("RGB : "+ r1 + " / " + g1 + " / " + b1);
//			System.out.println("P1 : "+ P1 + " /  P2 : " + P2 );
			color = new Color(r1,g1,b1);
			gb.setPaint(color);
			gb.draw(new Line2D.Double(P1,P2));
		}

			
		System.out.println("bufImg : " + bufImg);

		frame.contentPane.add(this,BorderLayout.CENTER);
		frame.show();
		
		short[] rt = new short[256];
		short[] gt = new short[256];
		short[] bt = new short[256];
		for (r1=0; r1<256; r1++)	{
			rt[r1] = (short)((r1+21)%255);
//			System.out.println(r1 +" = >"+  rt[r1]);

		}
		for (r1=0; r1<256; r1++)	{
			gt[r1] = (short)((r1+2)%255);
//			System.out.println(r1 +" = >"+  gt[r1]);
		}
		for (r1=0; r1<256; r1++)	{
			bt[r1] = (short)((r1+35)%255);
//			System.out.println(r1 +" = >"+  bt[r1]);
		}
		
		short[][] sourceTable = { rt, gt, bt };
		LookupTable table = new ShortLookupTable(0, sourceTable);
//		LookupTable table = new ShortLookupTable(0, rt);
		LookupOp opTable = new LookupOp(table,null);
		
		
		while (true)	{
			bufImg = opTable.filter(bufImg,null);
/*			try	{
        		MediaTracker tracker = new MediaTracker(this);
        		tracker.addImage(bufImg, 0);
        		tracker.waitForID(0);
       		 }
       		 catch ( Exception e )	{}
*/
       		 repaint();
        }
        	

	}
	

	public static void main(String[] args)	{		
		Exo4 panel = new Exo4();
	}

	
/**
	Main draw method
	*/
	
	public void paintComponent(Graphics g)	{
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		
		
		g2.drawImage(bufImg,0,0,null);

	}
	
	private		BufferedImage		bufImg;
	private		Graphics2D			gb;
	private		String[]			algoType;
	private		Color[]				algoColor;
	private		JLabel 				label;	
	private		JButton 			button1,button2,button3;		
	private		JPanel 				bPanel;
	private 	Point2D				P1,P2;
	private 	Point				rP1,rP2;
	private 	ApplicationFrame	frame;
	private 	VisuRaster			visuR;	
	private 	boolean				mouseP;
	private 	int					lineType, olineType, nbType;
	private		int				width, height;
	
}