// (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 BMWCanvas extends ACanvas {

	private int size;

	public BMWCanvas(Color c, int width, int height) {
		super(c, width, height);
		size = width;
	}

	public void draw(final int canvasAnimationTime) {
		Thread drawer = new Thread() {

			@Override
			public void run() {
				// 16 ops...
				setAnimationTime(canvasAnimationTime/16);
				Color c0 = Color.white, c1 = Color.blue, c2 = Color.lightGray, c3 = Color.black;
				int r = size / 3, x = size / 2, y = size / 2;	// size and position of badge
				int r1 = r / 2, th = r / 20;

				ACircle g0 = new ACircle(c3, x, y, r);		// black circle
				add(g0);
				g0.draw();

				ACircle g1 = new ACircle(c1, x, y, r1);	// blue circle
				add(g1);
				g1.draw();

				int w = 2 * r1;
				AArc a0 = new AArc(c0, x, y, w, w, 0, 90);		// white arc
				add(a0);
				a0.draw();
				AArc a1 = new AArc(c0, x, y, w, w, 180, 90);	// white arc
				add(a1);
				a1.draw();

				ABox b0 = new ABox(c2, x, y, th, w);			// lightGray cross
				add(b0);
				b0.draw();
				ABox b1 = new ABox(c2, x, y, w, th);			// lightGray cross
				add(b1);
				b1.draw();

				ACircle g2 = new ACircle(c2, x, y, r1);	// lightGray circle
				g2.setFill(false);
				g2.setLineWidth(th);
				add(g2);
				g2.draw();
				ACircle g3 = new ACircle(c2, x, y, r);	// lightGray circle
				g3.setFill(false);
				g3.setLineWidth(th);
				add(g3);
				g3.draw();

				int fontSize = (r - r1) / 4;
				int movexy = (r1 + (r - r1) / 2 - fontSize);

				Font font = new Font("Courier", Font.BOLD, fontSize);

				AText tB = new AText(c0, "B");
				add(tB);
				tB.draw();
				tB.moveUp(movexy);
				tB.rotate(x, y, -45);

				AText tM = new AText(c0, "M");
				add(tM);
				tM.draw();
				tM.moveUp(movexy);

				AText tW = new AText(c0, "W");
				add(tW);
				tW.draw();
				tW.moveUp(movexy);
				tW.rotate(x, y, 45);
			}
		};
		drawer.start();
	}

	public static void main(String[] args) {
		BMWCanvas canvas = new BMWCanvas(Color.red, 300, 300);
		JFrame frame = new JFrame("BMW");
		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(3000);
	}
}