« memefx: A Set of Rich - Freely Evolving - JavaFX Components | Main | Drop the Checkered Flag: Solution to JavaFX Puzzler #2 »

March 31, 2009

Comments

FeiCheng

sorry for posting so much times, I just want to make
it better! :)

import javafx.animation.Interpolator;
import javafx.animation.Timeline;
import javafx.animation.transition.AnimationPath;
import javafx.animation.transition.OrientationType;
import javafx.animation.transition.PathTransition;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;

/**
* @author FeiCheng
*/
var path = Path {
elements: [
MoveTo { x: 100 y: 100 },
ArcTo {
x : 50*java.lang.Math.sqrt(2), y : 50*java.lang.Math.sqrt(2)
radiusX : 50, radiusY :50
sweepFlag:true
absolute:false
},
ArcTo {
x : 50*java.lang.Math.sqrt(2), y : 50*java.lang.Math.sqrt(2)
radiusX : 50, radiusY :50
sweepFlag:false
absolute:false
},
ArcTo {
x : -50*java.lang.Math.sqrt(2), y : -50*java.lang.Math.sqrt(2)
radiusX : 50, radiusY :50
sweepFlag:false
absolute:false
},
ArcTo {
x : -50*java.lang.Math.sqrt(2), y : -50*java.lang.Math.sqrt(2)
radiusX : 50, radiusY :50
sweepFlag:true
absolute:false
},
]
stroke:Color.BLACK
}

var pathTransition : PathTransition;

var car : Ellipse = Ellipse {
radiusX : 20, radiusY : 10
fill: Color.BLUE
onMousePressed: function( e: MouseEvent ):Void {
if (not pathTransition.paused) {pathTransition.pause();}
else {pathTransition.play();}
}

}
pathTransition = PathTransition {
interpolate : Interpolator.LINEAR
duration: 10s node: car
path: AnimationPath.createFromPath(path)
orientation: OrientationType.ORTHOGONAL_TO_TANGENT
repeatCount:Timeline.INDEFINITE
}
pathTransition.play();

Stage {
title: "PathTransition Puzzler"
width: 600
height: 600
scene: Scene {
content: [path,car]
}
}

The comments to this entry are closed.

Categories