Affichage des articles dont le libellé est Animation. Afficher tous les articles
Affichage des articles dont le libellé est Animation. Afficher tous les articles

lundi 16 septembre 2013

Lambda and JavaFX 8.0

Updating my Mac with:
Now, let's try to play with Lambda …  and JavaFX 8.0

My first try is a classical replace of the ActionEvent of a button by a Lambda and a less classical call of an existing method by using method references.
And my second try is to rewrite Duke Anim with Lambda.

mercredi 22 juin 2011

Droid Anim – Android 3.0

When I wanted to try JavaFX 1.x and more particularly the animations, I wrote Duke Anim, and Duke Anim in JavaFX 1.3.
So when I wanted to try the new animation API in Android 3.0, I wrote Droid Anim.

jeudi 24 septembre 2009

Duke Anim JavaFX


import java.util.Random;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
//import javafx.scene.effect.Reflection;
//import javafx.scene.effect.SepiaTone;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.Scene;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;

/**
 * @author paddy
 */

class DukeAnimModel {
  
    public var imageURL = "{__DIR__}images/duke.png";
  
    public var x = 0;
    public var y = 0;

    var xTarget = 0;
    var yTarget = 0;

    var xTemp = 0;
    var yTemp = 0;

    public var anim =
    Timeline {
        autoReverse: false
        keyFrames: [
            KeyFrame {
                time: 0s
                values: [x => xTemp, y => yTemp]

            },
            KeyFrame {
                time: 1s
                //values: [x => 300 tween Interpolator.LINEAR,y => yTarget tween Interpolator.LINEAR]
                values: [x => xTarget tween
                    Interpolator.SPLINE(0,.5,.5,1),y => yTarget tween
                    Interpolator.SPLINE(0,.5,.5,1)]

                action: function(): Void{
                    println("at 1 second ...");

                    var generator = new Random();
                
                    //xTarget = (generator.nextFloat() * 400 + 1) as Integer;
                    xTarget = (
                    generator.nextFloat() * 240 + 1) as Integer;
                    println("xNext {xTarget} ");
                    //yTarget = (generator.nextFloat() * 300 + 1) as Integer;
                    yTarget = (
                    generator.nextFloat() * 320 + 1) as Integer;
                    println("yNext {yTarget} ");
                    xTemp=x;
                    yTemp=y;

                }
            },
        ]
        repeatCount: Timeline.INDEFINITE
    };
}

var dukeAnimModel = DukeAnimModel {}

dukeAnimModel.anim.play();


Stage {
    title: "Application title"
    width: 240  //400
    height: 320 //300
    scene: Scene {
        content: ImageView {
            transforms: Translate {
                x: bind dukeAnimModel.x
                y: bind dukeAnimModel.y
            }
            image: Image {
                url: dukeAnimModel.imageURL

            }
          /*  effect:Reflection{
                input: SepiaTone{
                }
            }
           */

        }
    }
    onClose: function(){
        println("exit");
    }
}