/*
 * Created on Apr 3, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package ps6;
import java.awt.Color;
import java.awt.Graphics2D;

/**
 * @author knorton
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class VisualProbe extends Gate {
	private Color		lo = Color.WHITE;
	private Color		hi = Color.RED;
	private Color		br = Color.BLACK;
	
	private Gate			input;
	private int			x,y,width,height;
	
	public VisualProbe(Gate input, int x, int y, int width, int height) {
		this(x,y,width,height);
		this.input = input;
	}
	
	public VisualProbe(int x, int y, int width, int height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
		
	public void update() {
	}
	
	private Color getColor() {
		float p = (float)this.input.getValue().getP(0);
		return new Color(
			this.lo.getRed()   + (int)(((float)this.hi.getRed() - (float)this.lo.getRed())*p),
			this.lo.getGreen() + (int)(((float)this.hi.getGreen() - (float)this.lo.getGreen())*p),
			this.lo.getBlue()  + (int)(((float)this.hi.getBlue() - (float)this.lo.getBlue())*p));
	}
	
	public void draw(Graphics2D g) {
		g.setColor(this.getColor());
		g.fillRect(x,y,width,height);
		
		g.setColor(this.br);
		g.drawRect(x,y,width,height);
	}
}
