/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Oracle Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package primitiveshapes;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import javafx.scene.text.Font;
import javafx.scene.paint.*;
import javafx.scene.text.*;
var object_size:Number = 70;
var color1 = Color.YELLOW;
var variable = 0.01;
var opacity = 1.0;
var op:Number[] = [0.5,0.5,0.5];
var selection:Boolean[] = [false,false,false];
var color_next = Color.YELLOWGREEN;
var color_back = Color.GRAY;
var forward = true;
var patch_color1 = Color.GOLD;
var patch_color2 = Color.GREEN;
var patch_color3 = Color.DARKRED;
var patch_color4 = Color.DARKBLUE;
var patch_color5 = Color.GRAY;
var st_color1 = patch_color1;
var st_color2 = patch_color2;
var st_color3 = patch_color3;
var st_color4 = patch_color4;
var st_color5 = patch_color5;
var timeline = Timeline {
repeatCount: 1
keyFrames : [
KeyFrame {
time : 2s
values : [
variable => 1.0 tween Interpolator.LINEAR
]
}
]
};
var timeline_forward = Timeline {
repeatCount: 1
keyFrames : [
KeyFrame {
time : 2s
values : [
opacity => 0.0 tween Interpolator.LINEAR
]
}
]
};
var timeline_backward = Timeline {
repeatCount: 1
keyFrames : [
KeyFrame {
time : 2s
values : [
opacity => 1.0 tween Interpolator.LINEAR
]
}
]
};
var fill_Linear:Paint = bind LinearGradient {
startX: 0
startY: 0
endX: variable
endY: 0
proportional: true
stops: [
Stop {
offset: 0.0
color: color1
},
Stop {
offset: 1.0
color: Color.WHITE
}
]
};
var fill_Radial:Paint = bind RadialGradient{
centerX: variable / 2
centerY: variable / 2
proportional: true
stops:[
Stop {
offset: 0.0
color: color1
},
Stop {
offset: 1.0
color: Color.WHITE
}
]
};
var selected = true;
var isGradient = true;
var shape11 = Circle {
centerX: 75,
centerY: 90
radius: 35
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind opacity
};
var shape12 = Arc {
centerX: 175,
centerY: 90
radiusX: 35,
radiusY: 35
startAngle: 90
length: 250
type: ArcType.ROUND
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind opacity
};
var shape13 = Ellipse {
centerX: 175
centerY: 190
radiusX: 35
radiusY: 25
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind opacity
};
var shape14 = Ellipse {
centerX: 75
centerY: 190
radiusX: 25
radiusY: 35
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind opacity
};
var shape21 = Rectangle {
x: 40
y: 55
width: 70
height: 70
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind 1 - opacity
};
var shape22 = Rectangle {
x: 140
y: 55
arcHeight:10
arcWidth:10
width: 70
height: 70
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind 1 - opacity
};
var shape23 = Polygon {
points: [
40,155,
110,190,
40,225
]
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind 1 - opacity
};
var shape24 = Polygon {
points: [
175,155,
210,155 + 0.2 * object_size,
210,155 + 0.8 * object_size,
175,155 + object_size,
140,155 + 0.8 * object_size,
140,155 + 0.2 * object_size,
]
fill: bind if(isGradient) {
color1
}
else if(selected) {
fill_Linear
} else {
fill_Radial
}
opacity: bind 1 - opacity
};
var font_tab = Font{
size: 15
name: "Arial"
};
var font_change = Font{
size: 15
name: "Arial Bold"
};
var text1 = Text {
font: font_tab
x: 15,
y: 22
content: "Linear"
fill: Color.WHITE
};
var text2 = Text {
font: font_change
x: 105,
y: 22
content: "Plain"
fill: Color.WHITE
};
var text3 = Text {
font: font_tab
x: 185,
y: 22
content: "Radial"
fill: Color.WHITE
};
Stage{
title: "Primitive Shapes"
width: 260
height: 320
scene: Scene{
fill: Color.BLACK
content: [
Rectangle {
x: 0,
y: 0
width: 80,
height: 30
fill: bind LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.BLACK
},
Stop {
offset: 0.5
color: Color.GRAY
},
Stop {
offset: 1.0
color: Color.BLACK
}
]
}
opacity: bind op[0]
arcHeight:5
arcWidth:5
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
isGradient = false;
selected = true;
op[0] = 1;
text1.font = font_change;
text3.font = font_tab;
text2.font = font_tab;
}
onMouseMoved: function( e: MouseEvent ):Void {
op[0] = 1;
}
onMouseExited: function( e: MouseEvent ):Void {
if(selection[0] != true)
op[0] = 0.4;
}
},
text1,
Rectangle {
x: 85,
y: 0
width: 80,
height: 30
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.BLACK
},
Stop {
offset: 0.5
color: Color.GRAY
},
Stop {
offset: 1.0
color: Color.BLACK
}
]
}
opacity: bind op[1]
arcHeight:5
arcWidth:5
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
isGradient = true;
selected = false;
op[1] = 1;
text3.font = font_tab;
text2.font = font_change;
text1.font = font_tab;
}
onMouseMoved: function( e: MouseEvent ):Void {
op[1] = 1;
}
onMouseExited: function( e: MouseEvent ):Void {
if(selection[1] != true)
op[1] = 0.4;
}
},
text2,
Rectangle {
x: 170
y: 0
width: 80
height: 30
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.BLACK
},
Stop {
offset: 0.5
color: Color.GRAY
},
Stop {
offset: 1.0
color: Color.BLACK
}
]
}
opacity: bind op[2]
arcHeight:5
arcWidth:5
onMouseClicked: function( e: MouseEvent ):Void {
timeline.playFromStart();
op[2] = 1;
isGradient = false;
selected = false;
text3.font = font_change;
text2.font = font_tab;
text1.font = font_tab;
}
onMouseMoved: function( e: MouseEvent ):Void {
op[2] = 1;
}
onMouseExited: function( e: MouseEvent ):Void {
op[2] = 0.4;
}
},
text3,
Rectangle {
x: 15,
y: 250
width: 20,
height: 20
fill: patch_color1
stroke: bind st_color1
arcHeight:5
arcWidth:5
onMouseMoved: function( e: MouseEvent ):Void {
st_color1 = Color.WHITE
}
onMouseExited: function(e: MouseEvent ):Void {
st_color1 = patch_color1
}
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
color1 = patch_color1
}
},
Rectangle {
x: 65,
y: 250
width: 20,
height: 20
fill: patch_color2
stroke: bind st_color2
arcHeight:5
arcWidth:5
onMouseMoved: function( e: MouseEvent ):Void {
st_color2 = Color.WHITE
}
onMouseExited: function(e: MouseEvent ):Void {
st_color2 = patch_color2
}
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
color1 = patch_color2
}
},
Rectangle {
x: 115,
y: 250
width: 20,
height: 20
fill: patch_color3
stroke: bind st_color3
arcHeight:5
arcWidth:5
onMouseMoved: function( e: MouseEvent ):Void {
st_color3 = Color.WHITE
}
onMouseExited: function(e: MouseEvent ):Void {
st_color3 = patch_color3
}
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
color1 = patch_color3
}
},
Rectangle {
x: 165,
y: 250
width: 20,
height: 20
fill: patch_color4
stroke: bind st_color4
arcHeight:5
arcWidth:5
onMouseMoved: function( e: MouseEvent ):Void {
st_color4 = Color.WHITE
}
onMouseExited: function(e: MouseEvent ):Void {
st_color4 = patch_color4
}
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
color1 = patch_color4
}
},
Rectangle {
x: 215,
y: 250
width: 20,
height: 20
fill: patch_color5
stroke: bind st_color5
arcHeight:5
arcWidth:5
onMouseMoved: function( e: MouseEvent ):Void {
st_color5 = Color.WHITE
}
onMouseExited: function(e: MouseEvent ):Void {
st_color5 = patch_color5
}
onMousePressed: function( e: MouseEvent ):Void {
timeline.playFromStart();
color1 = patch_color5
}
},
shape11,
shape12,
shape13,
shape14,
shape21,
shape22,
shape23,
shape24,
Polygon {
points : [ 240,140,230,130,230,150 ]
fill: bind color_next
onMousePressed: function( e: MouseEvent ):Void {
if(forward == true) {
timeline_forward.playFromStart();
color_next = Color.GRAY;
color_back = Color.YELLOWGREEN;
forward = false;
}
}
},
Polygon {
points : [ 10,140,20,130,20,150 ]
fill: bind color_back
onMousePressed: function( e: MouseEvent ):Void {
if(forward == false ) {
timeline_backward.playFromStart();
color_back = Color.GRAY;
color_next = Color.YELLOWGREEN;
forward = true;
}
}
},
]
}
}