Java Expert #3 のサンプル

一足早くサンプルだけ公開してしまいます。
2 枚のイメージが交互に表示されるというもの。Java SE 6u10 を使っていれば、背景を透明にすることができます。

解説は Java Expert で。

f:id:skrb:20081027162918p:image:h200:right
f:id:skrb:20081027162917p:image:h200

import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Frame;
import javafx.application.Stage;
import javafx.application.WindowStyle;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Translate;
 
var frontScale = 0.0;
var backScale = 0.0;
 
Frame {                      
    title: "Image Flicker"
    width: 160
    height: 240
    windowStyle: WindowStyle.TRANSPARENT
    visible: true
     
    stage: Stage {
        fill: null
        content: [
            ImageView {                       
                transform: [            
                    Translate {
                        x : bind 80 - 80 * frontScale
                        y : 0
                    },
                    Scale {
                        x: bind frontScale
                        y : 1.0
                    }
                ]
                image: Image {
                   url: __DIR__ + "macaron1.jpg" 
                }
            },
            ImageView {
                transform: [
                    Translate {
                        x : bind 80 - 80 * backScale
                        y : 0
                    },
                    Scale {
                        x: bind backScale
                        y : 1.0
                    }
                ]
                image: Image {
                   url: __DIR__ + "macaron2.jpg"
                }
            },
        ]
    }
}
 
var animator = Timeline {   
    repeatCount: Timeline.INDEFINITE
    keyFrames : [
        KeyFrame {
            time : 1s   
            values: [ 
                frontScale => 1.0 tween Interpolator.EASEOUT 
            ]
        },
        KeyFrame {
            time : 2s
            values: [ 
                frontScale => 0.0 tween Interpolator.EASEOUT, 
                backScale => 0
            ]
        },
        KeyFrame {
            time : 3s
            values: [ 
                backScale => 1.0 tween Interpolator.EASEOUT 
            ]
        },
        KeyFrame {
            time : 4s
            values: [ 
                backScale => 0.0 tween Interpolator.EASEOUT,
                frontScale => 0 
            ]
        }
    ]
}
animator.start();