2009年 1月 16日 金曜日
トップスピン
以前のハンズオンの課題のアニメーションで、「どうして、テニスボールじゃないの?」と言われて作成してみました。基本的にほとんど同じなのですが、背景にネットを使ったり、ボールにグラデーションをつけたりと、微妙に細工をしていています。
一応、ソースも貼り付けておきます。
package javafxapplication15;
import javafx.animation.*;
import javafx.ext.swing.*;
import javafx.scene.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.*;
import javafx.stage.*;
var interpolate = Interpolator.LINEAR;
var x = 0;
var y = 110.0;
var w = 10.0;
var h = 10.0;
var color = Color.LIME;
var opacity = 1.0;
var t = Timeline {
keyFrames: [
KeyFrame {
time: 0s
values: x => 0
},
KeyFrame {
time: 0.1s
timelines: [
Timeline {
keyFrames: [
KeyFrame {
time: 0s
values: [
w => 10.0,
h => 10.0
]
},
KeyFrame {
time: 0.2s
values: [
w => 15.0 tween interpolate
h => 15.0 tween interpolate
]
},
KeyFrame {
time: 0.4s
values: [
w => 40.0 //tween interpolate,
h => 37.0 //tween interpolate
]
},
KeyFrame {
time: 0.41s
values: [
w => 0
h => 0
]
}
]
}
]
},
KeyFrame {
time: 0.1s
values: x => 40 tween interpolate
},
KeyFrame {
time: 0.3s
values: x => 150 tween interpolate
},
KeyFrame {
time: 0.5s
values: x => 500 tween interpolate,
}
]
}
var t2 = Timeline {
keyFrames: [
KeyFrame {
time: 0s
values: y => 110
},
KeyFrame {
time: 0.3s
values: y => 350 tween interpolate
},
KeyFrame {
time: 0.5s
values: y => 150 tween interpolate
}
]
}
var buttons =
HBox {
content: [
SwingButton {
text: "Start"
action: function():Void {
t.playFromStart();
t2.playFromStart();
}
},
SwingButton {
text: "Stop"
action: function():Void {
t.stop();
t2.stop();
}
},
SwingButton {
text: "Pause"
action: function():Void {
t.pause();
t2.pause();
}
},
SwingButton {
text: "Resume"
action: function():Void {
t.play();
t2.play();
}
}
]
}
var ball = Group {
content: [
Ellipse {
centerX: bind x
centerY: bind y
radiusX: bind w
radiusY: bind h
fill: LinearGradient {
startX: 0.0,
startY: 0.0,
endX: 1.0,
endY: 0.0,
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.YELLOW
},
Stop {
offset: 0.1
color: Color.YELLOW
},
Stop {
offset: 0.2
color: Color.WHITE
},
Stop {
offset: 0.3
color: Color.YELLOW
},
Stop {
offset: 0.7
color: Color.YELLOW
},
Stop {
offset: 0.8
color: Color.WHITE
},
Stop {
offset: 0.9
color: Color.YELLOW
},
Stop {
offset: 1.0
color: Color.YELLOW}
]
}
opacity: bind opacity
}
]
}
var canvas =
Scene {
fill: Color.WHITE
content: [
VBox {
spacing: 10
content: [
ImageView {
image: Image {
url: "http://blogs.sun.com/kenji/resource/court.jpg"
}
},
buttons
]
},
ball
]
}
Stage {
width: 600
height: 500
visible: true
scene: canvas
}
Posted at 11:55午前 1 16, 2009 by kenji in JavaFX の素人 | 投稿されたコメント[2]
起動できませんでした。jfx.sfbay.sun.com なんとかがロードできないってエラーになってしまいます。
Posted by 片貝 on 1月月 16日, 2009年 at 12:28 午後 JST #
どうもありがとうございます。一応修正しておきました。JNLP の javafx runtime を URL を変更しました。
Posted by Kenji Tachibana on 1月月 19日, 2009年 at 04:36 午後 JST #