/* targetCanvas.java */

/**
* targetCanvas.java defines targetCanvas class
*/

import java.awt.*;
import java.applet.*;

public class targetCanvas extends Canvas {
	normalTarget applet;		
	Dimension r;
	int[] xhits = new int[0];
	int[] yhits = new int[0];
	int numberHits = 0;
	int height, width;

	public targetCanvas( normalTarget applet) {
		this.applet = applet;
		r =size(); // just so size is initialized.
		height = r.height;
		width = r.width;	
		}



	public int	getWidth() {
		return r.width;
		}
	
	public int getHeight() {
		return r.height;
		}
			

	public Dimension preferredSize(){
		Dimension d = new Dimension(250, 350);
		return d;

		}
	
	public void update(int x, int y) {
		
		}
	
	public void clearWinners() {
		
	}




	public void paint (Graphics g) {
			r = size();
		height= r.height;
		width = r.width;
		//System.out.println("height="+height+"width= "+width);
		g.setColor(Color.white);
		g.fillOval(width/2-80, height/2-80, 160, 160);
		g.setColor(Color.blue);
		g.fillOval(width/2-40, height/2-40, 80, 80);
		g.setColor(Color.red);
		g.fillOval(width/2-15, height/2-15, 30, 30);
		g.setColor(Color.green);
		for (int i=0; i < numberHits; i++) {
			g.fillOval(xhits[i]-3, yhits[i]-3, 6, 6);
			}	
	}


	public void plot(double x, double y) {
		int xscale, yscale;
		xscale = scalex(x, width, height);
		yscale = scaley(y, width, height);
		int[] xtemp = new int[numberHits];
		System.arraycopy( xhits, 0, xtemp, 0, numberHits);
		int[] ytemp = new int[numberHits];
		System.arraycopy( yhits, 0, ytemp, 0, numberHits);
		numberHits++;
		xhits = new int[numberHits];
		yhits = new int[numberHits];
		System.arraycopy( xtemp, 0, xhits, 0, numberHits-1);
		System.arraycopy( ytemp, 0, yhits, 0, numberHits-1);
		xhits[numberHits-1]=xscale;
		yhits[numberHits-1]=yscale;
		repaint();

		}

		private int scalex(double x ,  int width, int height) {
		return width/2+(int)(x*width/6);
		}

		private int scaley(double y, int width, int height) {
		return height/2+(int)(y*width/6); // keep x, y same scale!
		}
		
	public void clear() {
		numberHits =0;
		xhits = new int[0];
		yhits = new int[0];
		repaint();
		}

}
		
