ArcTo_RotateTrasition2
 
 
Code:

package javafxtemplate1;
// without a divider
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.PathTransition.OrientationType;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.Circle;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import javafx.animation.PathTransition;
import javafx.animation.RotateTransition;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.PathElement;
import javafx.util.Duration;
import javafx.util.converter.NumberStringConverter;
/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
//


@Override

public void start(Stage primaryStage)
{
Label label1 = new Label("Click On Red Ball");
label1.setLayoutX(10);label1.setLayoutY(220);
final Circle circle1 = new Circle();
circle1.setCenterX(-5);circle1.setCenterY(5);
circle1.setRadius(10.0f); circle1.setFill(Color.WHITE);
//
final Circle circle3 = new Circle();
circle3.setCenterX(200);circle3.setCenterY(200);
circle3.setRadius(30.0f); circle3.setFill(Color.RED);


PathElement[] path = squareOrbit();
Path track = new Path();
track.setStroke(Color.BROWN);
track.setStrokeWidth(10);
track.getElements().addAll(path);

Path divider = new Path();
divider.setStroke(Color.WHITE);
divider.setStrokeWidth(1);
divider.getStrokeDashArray().addAll(10.0, 10.0);
divider.getElements().addAll(path);
//
Path Spinner = new Path();
Spinner.setStroke(Color.YELLOW);
Spinner.setStrokeWidth(1);
Spinner.getStrokeDashArray().addAll(10.0, 10.0);
Spinner.getElements().addAll(path);

//

PathTransition anim = new PathTransition();
anim.setNode(circle1);// circle object
anim.setPath(track);// track
anim.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
anim.setInterpolator(Interpolator.LINEAR);
anim.setDuration(new Duration(6000));
anim.setCycleCount(Timeline.INDEFINITE);
//
RotateTransition spin = new RotateTransition();
spin.setNode(divider);
spin.setFromAngle(0);
spin.setToAngle(360);
spin.setInterpolator(Interpolator.LINEAR);
spin.setCycleCount(Timeline.INDEFINITE);
spin.setDuration(new Duration(3000));
//

Group root = new Group();
root.getChildren().addAll(label1,circle3,divider, circle1,Spinner);
//root.getChildren().addAll(track, circle1);
//root.getChildren().addAll(divider, circle1);
root.setTranslateX(50);
root.setTranslateY(50);
root.setOnMouseClicked(e ->
{
Animation.Status status1 = anim.getStatus();
Animation.Status status2 = spin.getStatus();
if (status1 == Animation.Status.RUNNING &&
status1 != Animation.Status.PAUSED){
anim.pause();}

else{
anim.play();
}
//
if (status2 == Animation.Status.RUNNING &&
status2 != Animation.Status.PAUSED){
spin.pause();}

else{
spin.play(); }
});
Scene scene = new Scene(root, 500, 500, Color.DARKGRAY);

primaryStage.setTitle("PathTransition Demo");
primaryStage.setScene(scene);
primaryStage.show();
}
private PathElement[] squareOrbit()
{
// ArcTo.ArcTo(double,double,double,double,double,boolean,boolean)
//x, y, XAxis Rotation
PathElement[] path =
{

new MoveTo(0, 300),
new ArcTo(100, 100, 210, 100, 400, false, false),
new LineTo(300, 400),
new ArcTo(100, 100, 0, 400, 300, false, false),
new LineTo(400, 100),
new ArcTo(100, 100, 0, 300, 0, false, false),
new LineTo(100, 0),
new ArcTo(100, 100, 0, 0, 100, false, false),
new LineTo(0, 300),
new ClosePath()
};
return path;
}
public static void main(String[] args) {
launch(args);

}

}
 

 
Displays: