1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/**
* @author Alex
*/
public class TextBoxDansant extends CustomNode {
public-init var width: Number = 120;
public-init var height: Number = 30;
public-init var name: String = "Schumi";
var tb: TextBox;
override public function create(): Node {
Stack {
content: [
Rectangle {
// cache: true
width: width height: height
arcWidth: 10 arcHeight: 10
// fill: Color.BLACK
fill: LinearGradient {
startX : 0.0
startY : 0.0 endX : .0
endY : 1.0
stops: [
Stop {
color : Color.GRAY
offset: 0.0
},
Stop {
color : Color.BLACK
offset: .49
},
Stop {
color : Color.BLACK
offset: .51
},
Stop {
color : Color.GRAY
offset: 1.
}
]
}
}
VBox {
spacing: 2
hpos: HPos.CENTER
vpos: VPos.CENTER
nodeHPos: HPos.CENTER
content: [
Label {
textFill: Color.ORANGE
text: name
font: Font.font("Arial bold", 11)
}
tb = TextBox {
font: Font.font("Arial", 10)
layoutInfo: LayoutInfo {
width: width -10
height: 18
}
}
]
}
]
}
}
function update() {
def cal = Calendar.getInstance();
tb.text = "{%tT cal}.{cal.get(Calendar.MILLISECOND)}"
}
}
function runChrono(tbd: TextBoxDansant) {
Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame {
canSkip: true
time: .1s;
action: function(): Void {
tbd.update()
}
}
}.playFromStart();
}
function run() {
def drivers = [
"Hamilton",
"Button",
"Vettel",
"Alonso",
"Badoer",
"Weber",
"Kubica",
"Rosberg",
"Bourdais"
];
def S=2; def W = 90; def H = 40;
def path = [
MoveTo { x: 50*S y: 212*S },
LineTo { x: 80*S y: 128*S },
QuadCurveTo { controlX: 82*S controlY: 123*S
x: 98*S y: 124*S },
LineTo { x: 107*S y: 127*S },
CubicCurveTo { controlX1: 148*S controlY1: 147*S
controlX2: 56*S controlY2: 225*S
x: 120*S y: 254*S },
LineTo { x: 141*S y: 267*S },
CubicCurveTo { controlX1: 154*S controlY1: 277*S
controlX2: 143*S controlY2: 300*S
x: 131*S y: 295*S },
LineTo { x: 84*S y: 278*S },
QuadCurveTo { controlX: 34*S controlY: 255*S
x: 43*S y: 231*S },
LineTo { x: 50*S y: 212*S },
ClosePath {},
];
def tbds: TextBoxDansant[] = for (driver in drivers) TextBoxDansant{
width: W height: H name: driver
translateX: -50 translateY: 300 + indexof driver *( H + 10)
};
def track = Path {
stroke: Color.DARKGRAY
strokeWidth: 20*S
elements: path
};
def line = Path {
stroke: Color.WHITE
strokeWidth: 2
strokeDashArray: [ 20, 15 ]
elements: path
};
def startLines = for (tbd in tbds) ShapeIntersect {
def _tmp_init = tbd.update();
a: Rectangle {
x: 0 y: tbd.translateY + H/2-1
width: tbd.translateX height: 2
}
b: track
fill: Color.TRANSPARENT
}
def pathAnims: PathTransition[] = for(tbd in tbds) PathTransition {
node: tbd
path: AnimationPath.createFromPath(track)
orientation: OrientationType.NONE
interpolator: Interpolator.LINEAR
duration: 10s
repeatCount: Timeline.INDEFINITE
}
def finishLine = Timeline {
keyFrames: for (tbd in tbds) KeyFrame {
def _n = indexof tbd;
time: _n*.5s;
action: function(): Void {
pathAnims[_n].stop();
}
values: [
]
}
}
Stage {
title : "TB Chanpionship"
scene: Scene {
width: 550
height: 600
content: [
Rectangle {
width: 600
height: 600
fill: Color.GREEN
}
HBox {
spacing: 50
hpos: HPos.CENTER
content: [
Button {
text: "Start"
action: function() {
Timeline {
keyFrames: for (tbd in tbds) KeyFrame {
def n = indexof tbd;
// def _tbd = tbd;
// def bounds = startLines[n].boundsInLocal;
time: n*1s;
action: function(): Void {
pathAnims[n].playFromStart();
runChrono(tbd);
}
// values: [
// _tbd.translateX => bounds.maxX - W/2
// ]
}
}.playFromStart();
}
}
Button {
text: "Stop"
action: function() {
finishLine.playFromStart();
}
}
]
}
Group {
translateX: 80
translateY: -200
content: [
startLines,
track,
line,
tbds
]
}
]
}
}
} |