// (c) Academic Java. All rights reserved.
// See http://academicjava.com/animations/conditions.html for conditions of use
package animations;

import java.awt.*;
import javax.swing.*;
import org.academicjava.animation.*;

public class DartsCanvas extends ACanvas {

	public DartsCanvas(Color c, int width, int height) {
		super(c, width, height);
	}

	public void draw() {
		setAnimationTime(200);

		ACircle c = new ACircle(Color.black, 100);
		add(c);
		c.draw();

		int d0 = 150, d1 = 90, th = 12;
		int[] numbers = new int[]{20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5};
		boolean black = false;

		for (int i = 0; i < 20; i++, black = !black) {
			Color c0 = Color.black, c1 = Color.red;
			if (!black) {
				c0 = new Color(255, 255, 128);	// off-white
				c1 = Color.green;
			}

			AArc a0 = new AArc(c1, d0, d0, -9, 18);
			add(a0);
			a0.rotate(i * 18);
			a0.draw();

			AArc a1 = new AArc(c0, d0 - th, d0 - th, -9, 18);
			add(a1);
			a1.rotate(i * 18);
			a1.draw();

			AArc a2 = new AArc(c1, d1, d1, -9, 18);
			add(a2);
			a2.rotate(i * 18);
			a2.draw();

			AArc a3 = new AArc(c0, d1 - th, d1 - th, -9, 18);
			add(a3);
			a3.rotate(i * 18);
			a3.draw();

			AText num = new AText(Color.lightGray, 125, 40, "" + numbers[i], new Font("Helvetica", Font.BOLD, 16));
			add(num);
			num.rotate(125, 125, i * 18);
			num.draw();
		}

		ACircle c25 = new ACircle(Color.green, 7);
		add(c25);
		c25.draw();

		ACircle c50 = new ACircle(Color.red, 3);
		add(c50);
		c50.draw();

		Color c2 = Color.gray;
		ACircle w0 = new ACircle(c2, d0 / 2);
		add(w0);
		w0.setFill(false);
		w0.setLineWidth(1);
		w0.draw();
		ACircle w1 = new ACircle(c2, d0 / 2 - th / 2);
		add(w1);
		w1.setFill(false);
		w1.setLineWidth(1);
		w1.draw();
		ACircle w2 = new ACircle(c2, d1 / 2);
		add(w2);
		w2.setFill(false);
		w2.setLineWidth(1);
		w2.draw();
		ACircle w3 = new ACircle(c2, d1 / 2 - th / 2);
		add(w3);
		w3.setFill(false);
		w3.setLineWidth(1);
		w3.draw();
		ACircle w4 = new ACircle(c2, 7);
		add(w4);
		w4.setFill(false);
		w4.setLineWidth(1);
		w4.draw();
		ACircle w5 = new ACircle(c2, 3);
		add(w5);
		w5.setFill(false);
		w5.setLineWidth(1);
		w5.draw();
	}

	public static void main(String[] args) {
		DartsCanvas canvas = new DartsCanvas(Color.gray, 250, 250);
		JFrame frame = new JFrame("Darts");
		Container cp = frame.getContentPane();
		cp.add(canvas, BorderLayout.CENTER);

		frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);

		canvas.draw();
	}
}