import javafx.application.Application; import javafx.animation.Animation; import javafx.animation.RotateTransition; import javafx.animation.Interpolator; import javafx.util.Duration; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.Node; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.shape.Path; import javafx.scene.shape.MoveTo; import javafx.scene.shape.LineTo; import javafx.scene.shape.ClosePath; public class Test2 extends Application { final double SW = 8.0; final double RX = 150.0; final double RY = 150.0; final double RW = 50.0; final double RH = 50.0; final double NW = 400.0; final double NH = 300.0; public void start(Stage stage) { Group g1 = makeSet(true); Group g2 = makeSet(false); g2.setTranslateY(NH); Group root = new Group(g1, g2); Scene scene = new Scene(root, NW, NH*2); stage.setScene(scene); stage.show(); animate(g1); animate(g2); } void animate(Node n) { RotateTransition rt = new RotateTransition(Duration.seconds(2), n); rt.setByAngle(360); rt.setCycleCount(Animation.INDEFINITE); rt.setInterpolator(Interpolator.LINEAR); rt.play(); } Group makeSet(boolean useRect) { Node r1 = makeNode(RX, RY, RW, RH, SW, useRect); r1.setScaleX(3.0); r1.setScaleY(2.0); Path p1 = makeOutline(RX, RY, RW, RH, SW); p1.setScaleX(3.0); p1.setScaleY(2.0); return new Group(r1, p1); } Path makeOutline(double x, double y, double w, double h, double sw) { double hsw = sw/2.0; Path p = new Path( new MoveTo(x -hsw, y -hsw), new LineTo(x+w+hsw, y -hsw), new LineTo(x+w+hsw, y+h+hsw), new LineTo(x -hsw, y+h+hsw), new ClosePath(), new MoveTo(x +hsw, y +hsw), new LineTo(x+w-hsw, y +hsw), new LineTo(x+w-hsw, y+h-hsw), new LineTo(x +hsw, y+h-hsw), new ClosePath() ); p.setFill(null); p.setStroke(Color.BLUE); p.setStrokeWidth(1.0); return p; } Node makeNode(double x, double y, double w, double h, double sw, boolean useRect) { return useRect ? makeRect(x, y, w, h, sw) : makePath(x, y, w, h, sw); } Rectangle makeRect(double x, double y, double w, double h, double sw) { Rectangle r = new Rectangle(x, y, w, h); r.setFill(null); r.setStroke(Color.CYAN); r.setStrokeWidth(sw); return r; } Path makePath(double x, double y, double w, double h, double sw) { Path p = new Path( new MoveTo(x, y), new LineTo(x+w, y), new LineTo(x+w, y+h), new LineTo(x, y+h), new ClosePath() ); p.setFill(null); p.setStroke(Color.YELLOW); p.setStrokeWidth(sw); return p; } }