/*
* 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 flyingsaucer;
import javafx.animation.*;
import javafx.stage.*;
import javafx.stage.AppletStageExtension;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.input.*;
import javafx.scene.image.*;
import javafx.scene.paint.*;
import javafx.scene.transform.*;
import javafx.scene.media.*;
import java.lang.Math;
def ss = 3.0;
var s = 1.0/ss;
var soffx = -200;
var soffy = -50;
var stage:Stage;
var alreadyStarted = false;
var offImage = Image { url: "{__DIR__}FlyingSaucerUnLighted.png" };
var onImage = Image { url: "{__DIR__}FlyingSaucerLighted.png" };
var onImageNoRocket = Image { url: "{__DIR__}FlyingSaucerLightedNoRocket.png" };
var currentImage = offImage;
var rot_angle = 0.0;
var animating = false;
function doFly(xstart:Number,ystart:Number):Void {
animating = true;
var xoff = 0;
var yoff = 0;
var x = xstart-xoff;
var y = ystart-yoff;
var fly = Timeline { keyFrames: [
KeyFrame { time:0s action: function(){ flyTo(x,y-100) } },
KeyFrame { time: 1.0s action: doHover },
KeyFrame { time: 4s action: function() { flyTo(50-xoff,50-yoff) } },
KeyFrame { time: 5s action: doHover },
KeyFrame { time: 8s action: function() { flyTo(1000-xoff,300-yoff) } },
KeyFrame { time: 9s action: doHover },
KeyFrame { time: 12s action: function() { flyTo(100-xoff,700-yoff) } },
KeyFrame { time: 13s action: doHover },
KeyFrame { time: 16s action: function() { flyTo(500-xoff,500-yoff) } },
KeyFrame { time: 17s action: doZoomIn },
KeyFrame { time: 18s action: doHover },
KeyFrame { time: 21s action: function():Void { doZoomHome(xstart,ystart) } },
KeyFrame { time: 22s action: function():Void { funnyDrop(); } },
KeyFrame { time: 28.1s
action: function() {
currentImage = offImage;
stage.close();
alreadyStarted = false;
animating = false;
}
}
]
};
fly.play();
}
var scene:Scene = Scene {
fill: Color.BLACK
content:
Group {
translateX: bind soffx
translateY: bind soffy
content: ImageView {
transforms: bind [
Transform.scale(s,s,300,150),
Transform.rotate(rot_angle,300,150)
]
image: bind currentImage
onMousePressed: function(e:MouseEvent):Void {
currentImage = onImage;
println("stage starting at: {stage.x},{stage.y}");
doFly(stage.x,stage.y);
}
}
}
};
scene.fill = Color.BLACK;
if(AppletStageExtension.appletDragSupported) {
scene.fill = Color.BLACK
} else {
scene.fill = null;
}
stage = Stage {
x: 400
y: 300
width: 200
height: 200
style: StageStyle.TRANSPARENT
scene: scene
extensions: [
AppletStageExtension {
shouldDragStart: function(e: MouseEvent): Boolean {
return e.primaryButtonDown and not alreadyStarted;
}
onDragStarted: function(): Void {
scene.fill = null;
}
onDragFinished: function(): Void {
alreadyStarted = true;
currentImage = onImage;
tx = stage.x;
ty = stage.y;
scene.fill = null;
doFly(stage.x,stage.y);
}
onAppletRestored: function(): Void {
scene.fill = Color.BLACK
}
useDefaultClose: false
}
]
};
function getCurrentStageX():Number {
return stage.x;
}
var tx = 400.0;
var ty = 300.0;
var t = 0.0 on replace {
if(animating) {
stage.x = Math.sin(Math.toRadians(t*2))*50 + tx;
stage.y = Math.cos(Math.toRadians(t))*50 + ty;
}
}
function doHover():Void {
tx = stage.x;
ty = stage.y;
var hover = Timeline {
keyFrames: [
at(0.0s) { t=> 0},
at(1.0s) { t=> 360}
]
repeatCount: 3
};
hover.play();
}
function flyTo(ex:Number, ey:Number) {
var sx = stage.x;
var sy = stage.y;
var move = Timeline { keyFrames: [
at(0.0s) { stage.x => sx },
at(0.0s) { stage.y => sy },
at(1.0s) { stage.x => ex },
at(1.0s) { stage.y => ey },
]};
move.play();
}
function doZoomIn():Void {
stage.width = 600;
soffx = 0;
stage.x = stage.x - 200;
stage.height = 600;
soffy = 0;
stage.y = stage.y - 50;
var zoom = Timeline { keyFrames: [
at(0s) { s => 1.0/ss },
at(1s) { s => 3.0/ss },
]
};
zoom.play();
}
function doZoomHome(x:Number,y:Number):Void {
var zoom = Timeline { keyFrames: [
at(0s) { s => 3.0/ss },
at(0s) { stage.x => stage.x },
at(0s) { stage.y => stage.y },
at(0.3s) { s => 1.0/ss },
at(0.3s) { stage.x => x-200 },
at(0.3s) { stage.y => y-50-100 },
KeyFrame {
time: 0.31s
action: function() {
stage.width = 200;
stage.height = 200;
stage.x += 200;
stage.y += 50;
soffx = -200;
soffy = -50;
}
}
]
};
zoom.play();
}
function doLower():Void {
var y = stage.y;
var anim = Timeline {
keyFrames: [
at(0s) { stage.x => stage.x},
at(0s) { stage.y => y },
at(1s) { stage.x => stage.x},
at(1s) { stage.y => y+100 }
]
};
anim.play();
}
function funnyDrop():Void {
var y = stage.y;
var anim = Timeline {
keyFrames: [
at(0s) { stage.y => y },
at(0s) { currentImage => onImage },
at(0.5s) { currentImage => onImageNoRocket },
at(0.7s) { currentImage => onImage },
at(0.9s) { currentImage => onImageNoRocket },
at(1.0s) { currentImage => onImage },
at(1.2s) { currentImage => onImageNoRocket },
at(1.4s) { currentImage => onImage },
at(1.6s) { currentImage => onImageNoRocket },
at(2.0s) { stage.y => y },
at(2.2s) { stage.y => y+100 },
at(2.3s) { stage.y => y+80 },
at(2.4s) { stage.y => y+100 },
at(2.4s) { rot_angle => 0 },
at(2.5s) { rot_angle => -30 },
at(2.6s) { rot_angle => 15 },
at(2.7s) { rot_angle => -15 },
at(4.2s) { rot_angle => -15 },
at(4.5s) { rot_angle => 10 },
at(4.55s) { rot_angle => 0 },
]
};
anim.play();
}