package express.lines;

import java.awt.Graphics;
import java.awt.Color;
import java.util.Date;
import express.awt.*;

public class Line002 extends ChangingColorLine  {

	int d = -150;
	int t =0;

	public Line002(int x, int y, long t, Color lineColor) {		
		super(x,y,t,lineColor);	

	}
	
	public void redraw(Graphics g) {

		if (changing) {
			currentTime = new Date().getTime(); 
			lineColor = changeColor(currentTime);
		}
		
		g.setColor(lineColor);
		for (int i = 0, len = this.size()-1; i < len; i=i+1) {
			g.drawLine(
					  ((TimedPoint)(this.elementAt(i))).x - d/6,
					((TimedPoint)(this.elementAt(i))).y - d,
					((TimedPoint)(this.elementAt(i+1))).x - d/6,
					((TimedPoint)(this.elementAt(i+1))).y - d);
		}
		
	}
	
	public Color changeColor(long currentTime) {
		
		if (living) {
		d = d + 4;
		this.currentTime = currentTime;
		long differenceTime = currentTime - startTime;
		t = (int)(0.0002*differenceTime);
		}

		if (d>150) living = false;


		R = (int)(R-t);
		if (R < 0) {R = 0;}

		G = (int)(G+t*2);
		if (G > 255) {G = 255;}

		B = (int)(B+t/2);
		if (B > 255) {B = 255;}
		
		
		lineColor = new Color(R,G,B);
		return lineColor;	
	
	}
	
}
