MoveTo_LineTo_ArcTo1
  • MoveTo: specified x and y coordinates of the current point
  • new ClosePath(),
    new MoveTo(300,100),
    new LineTo(300,-50),
  • new ClosePath(),
    new MoveTo(300,10), new MoveTo(300,10)
  • AutoReverse was set to be true
Template Code :

package javafxtemplate1;
// Path__RotationTransition
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.PathTransition;
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.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import javafx.animation.RotateTransition;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.Circle;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.HLineTo;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.PathElement;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.VLineTo;
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(50);label1.setLayoutY(180);

// PathElement array of mixed getElements
final Circle circle1 = new Circle();
circle1.setCenterX(10);circle1.setCenterY(10);
circle1.setRadius(10.0f); circle1.setFill(Color.WHITE);
PathElement[] path = squareOrbit();
Path track = new Path();
track.setStroke(Color.BROWN);
track.setStrokeWidth(10);
track.getElements().addAll(path);

RotateTransition spin = new RotateTransition();
spin.setNode(label1);
spin.setFromAngle(0);
spin.setToAngle(180);
spin.setRate(2.0);
spin.setInterpolator(Interpolator.LINEAR);
spin.setCycleCount(Timeline.INDEFINITE);
spin.setDuration(new Duration(5000));
spin.setAutoReverse(true);
//
PathTransition anim = new PathTransition();
anim.setNode(circle1);
//anim.setFromAngle(0);
//anim.setToAngle(360);// clock spin
anim.setPath(track);
anim.setInterpolator(Interpolator.LINEAR);
anim.setCycleCount(Timeline.INDEFINITE);
anim.setDuration(new Duration(5000));
anim.setAutoReverse(true);
//

Group root = new Group();
root.getChildren().addAll(label1,circle1, track);

root.setTranslateX(50);
root.setTranslateY(10);
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 PathElement[] squareOrbit()
{

PathElement[] path =
{
new MoveTo(10,100),
new LineTo(100,10),new ClosePath(),
new ArcTo(100, 100, 100,150,100,false,false),
new ArcTo(100, 100, 100,300,100 ,false,false),
new ClosePath(),
// try different combinations
new MoveTo(300,10),
new LineTo(300,100),

};
return path;
}

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

}

}

Typical runtime displays

 

Test permutation and Combinations

Code : 1

// eyeglass1
PathElement[] path =
{
new MoveTo(10,100), // zero to 300 streched
new LineTo(100,10),new ClosePath(),
new ArcTo(100, 100, 100,150,100,false,false),
new ArcTo(100, 100, 100,300,100 ,false,false),
new ClosePath(),
new MoveTo(300,100),
new LineTo(300,-50),


};
return path;
}

Displays:

Code 2 :

//eyeglass2
PathElement[] path =
{
new MoveTo(10,100), // zero to 300 streched
new LineTo(100,10),new ClosePath(),
new ArcTo(100, 100, 100,150,100,false,false),
new ArcTo(100, 100, 100,300,100 ,false,false),
new ClosePath(),
new MoveTo(300,10),
new LineTo(300,100),

};
return path;
}

Code 3:

//eyeglass3
PathElement[] path =
{
new MoveTo(10,100), // zero to 300 streched
new LineTo(100,10),new ClosePath(),
new ArcTo(100, 100, 100,150,100,false,false),
new ArcTo(100, 100, 100,300,100 ,false,false),
new ClosePath(),
new MoveTo(300,10),
new ArcTo(100, 0, 150, 300,100,false,false),


};
return path;
}

Runtime animation :

2)

3)

 

4)Trasnistion step at new ArcTo 100, was initiated after new LinTo 100

The cursor is at the intersection of "ArcTo End 100-ArctTo starts 100" path elements