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.scene.shape.LineTo; import javafx.scene.shape.PathElement; import javafx.util.Duration; /** * * @author Manas9 */ public class JavaFXTemplate1 extends Application { // @Override public void start(Stage primaryStage) { /* ImageView car = new ImageView(); car.setImage(new Image("file:res/car.gif")); car.setX(-car.getImage().getWidth() / 2); car.setY(300 - car.getImage().getHeight()); car.setRotate(90); // */ //final Circle circle1 = new Circle(10,10,10); final Circle circle1 = new Circle(); circle1.setCenterX(-5);circle1.setCenterY(5); 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); Path divider = new Path(); divider.setStroke(Color.WHITE); divider.setStrokeWidth(1); divider.getStrokeDashArray().addAll(10.0, 10.0); divider.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); Group root = new Group(); root.getChildren().addAll(track, divider, circle1); //root.getChildren().addAll(track, circle1); //root.getChildren().addAll(divider, circle1); root.setTranslateX(50); root.setTranslateY(50); root.setOnMouseClicked(me -> { Animation.Status status = anim.getStatus(); if (status == Animation.Status.RUNNING && status != Animation.Status.PAUSED) anim.pause(); else anim.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) PathElement[] path = { new MoveTo(0, 300), new ArcTo(50, 50, 50, 50,50,false,false), new ClosePath() }; return path; } public static void main(String[] args) { launch(args); } }