CubicCurve_Rotation2
 
 
Code :

package javafxtemplate1;
// CubicCurve Rotation
import javafx.animation.Animation;
import javafx.animation.Interpolator;
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.ClosePath;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import javafx.animation.RotateTransition;
import javafx.scene.control.Label;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.PathElement;
import javafx.scene.shape.StrokeLineCap;
import javafx.util.Duration;

/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
//


@Override

public void start(Stage primaryStage)
{
Label label1 = new Label("Click On the screen");
label1.setLayoutX(10);label1.setLayoutY(220);
//
CubicCurve cubic1 =createStartingCurve();
CubicCurve cubic2 =createStartingCurve();
// PathElement array of mixed getElements
PathElement[] path = squareOrbit();
Path track = new Path();
track.setStroke(Color.BROWN);
track.setStrokeWidth(10);
track.getElements().addAll(path);

RotateTransition spin = new RotateTransition();
spin.setNode(cubic1);
spin.setFromAngle(0);
spin.setToAngle(-360);// anti-clock spin
spin.setInterpolator(Interpolator.LINEAR);
spin.setCycleCount(Timeline.INDEFINITE);
spin.setDuration(new Duration(5000));
//
RotateTransition anim = new RotateTransition();
anim.setNode(cubic2);
anim.setFromAngle(0);
anim.setToAngle(360);// clock spin
anim.setInterpolator(Interpolator.LINEAR);
anim.setCycleCount(Timeline.INDEFINITE);
anim.setDuration(new Duration(5000));
//

Group root = new Group();
root.getChildren().addAll(label1,cubic2, cubic1);
//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();
//track.visibleProperty().set(true);
}
else{
spin.play();
// track.visibleProperty().set(false);
}
});
Scene scene = new Scene(root, 500, 500, Color.DARKGRAY);

primaryStage.setTitle("PathTransition Demo");
primaryStage.setScene(scene);
primaryStage.show();
}
//
private CubicCurve createStartingCurve() {
CubicCurve curve = new CubicCurve();
curve.setStartX(100);
curve.setStartY(100);
curve.setControlX1(150);
curve.setControlY1(50);
curve.setControlX2(250);
curve.setControlY2(150);
curve.setEndX(300);
curve.setEndY(100);
curve.setStroke(Color.FORESTGREEN);
curve.setStrokeWidth(4);
curve.setStrokeLineCap(StrokeLineCap.ROUND);
curve.setFill(Color.CORNSILK.deriveColor(0, 1.2, 1, 0.6));
return curve;
}

//
private PathElement[] squareOrbit()
{
// ArcTo.ArcTo(double,double,double,double,double,boolean,boolean)
//x, y, XAxis Rotation
//CubicCurveTo curve = new CubicCurveTo();
//curve= createStartingCurve();
PathElement[] path =
{

new MoveTo(0, 200), // zero to 300 streched
//straight line arcto
//new ArcTo(20,20,100,100,0,false,false),
new CubicCurveTo(0, 0,150,250,150,50),
new ClosePath()

};
return path;
}

public static void main(String[] args) {
launch(args);

}

}
 

Runtime Displays: