package carbadges;

import javafx.animation.Timeline;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.transform.Transform;

public class BMW extends CustomNode {

	def stageSize = 250.0;
	def centerStage = stageSize / 2;

	def r = stageSize / 3.0;
	def r1 = r / 2.0;
	def th = r / 20.0;

	public override function create(): Node {
		return Group {
			content: [
				Rectangle {
					width: stageSize
					height: stageSize
					fill: Color.RED
				}
				Group {
					content: [
						Circle {
							centerX: centerStage
							centerY: centerStage
							radius: bind rblack
							fill: Color.BLACK
						}
						Circle {
							centerX: centerStage
							centerY: centerStage
							radius: bind rblue
							fill: Color.BLUE
						}
						Arc {
							centerX: centerStage
							centerY: centerStage
							radiusX: bind arcr
							radiusY: bind arcr
							startAngle: 0
							length: 90
							type: ArcType.ROUND
							fill: Color.WHITE
						}
						Arc {
							centerX: centerStage
							centerY: centerStage
							radiusX: bind arcr
							radiusY: bind arcr
							startAngle: 180
							length: 90
							type: ArcType.ROUND
							fill: Color.WHITE
						}

						Rectangle {
							x: centerStage
							y: centerStage - r1
							width: bind dth
							height: 2 * r1
							fill: Color.SILVER
						}
						Rectangle {
							x: centerStage - r1
							y: centerStage
							width: 2 * r1
							height: bind dth
							fill: Color.SILVER
						}
						Circle {
							centerX: centerStage
							centerY: centerStage
							radius: bind dr1
							fill: null
							stroke: Color.SILVER
							strokeWidth: th
						}
						Circle {
							centerX: centerStage
							centerY: centerStage
							radius: bind dr
							fill: null
							stroke: Color.SILVER
							strokeWidth: th
						}
						Text {
							font: Font {
								size: (r - r1) * 3 / 4
							}
							x: centerStage - 10
							y: centerStage - r1 - 8
							content: "B"
							fill: Color.WHITE
							opacity: bind opB
							transforms: bind Transform.rotate(rotAngleB,centerStage,centerStage)
						}
						Text {
							font: Font {
								size: (r - r1) * 3 / 4
							}
							x: centerStage - 12
							y: centerStage - r1 - 8
							content: "M"
							fill: Color.WHITE
							opacity: bind opM
						}
						Text {
							font: Font {
								size: (r - r1) * 3 / 4
							}
							x: centerStage - 12
							y: centerStage - r1 - 8
							content: "W"
							fill: Color.WHITE
							opacity: bind opW
							transforms: bind Transform.rotate(rotAngleW,centerStage,centerStage)
						}

					]
					rotate: bind gr

				} // group
			] // return group content
		}; // return group

	} // create

	var opB = 0.0;
	var opM = 0.0;
	var opW = 0.0;
	var rotAngleB = 0.0;
	var rotAngleW = 0.0;
	var rblack = 0.0;
	var rblue = 0.0;
	var arcr = 0.0;
	var dth = 0.0;
	var dr = 0.0;
	var dr1 = 0.0;
	var gr = 0.0;

	public var timeline:Timeline =
	Timeline {
		keyFrames: [
at (0s) {rblack => 0.0;}
		at (1s) {rblack => r; rblue=>0.0}
		at (2s) {rblue => r1; arcr=>0.0}
		at (4s) {arcr=>r1; dth=>0.0; dr=>0.0; dr1=>0.0}
		at (6s) {dth=>th; dr=>r; dr1=>r1; opB=>0.0;}
		at (7s) {opB=>1.0;rotAngleB=>0.0}
		at (8s) {rotAngleB=>-45; opM=>0.0;}
		at (9s) {opM=>1.0;opW=>0.0;}
		at (10s) {opW=>1.0; rotAngleW => 0.0;}
		at (11s) {rotAngleW => 45; gr=>0.0;}
		at (12s) {gr=>360}
		]
	}
} // class