//DEPS org.openjfx:javafx-graphics:11.0.2:${os.detected.jfxname} import java.util.ArrayList; import javafx.animation.*; import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.effect.*; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.shape.*; import javafx.stage.*; import javafx.util.Duration; public class SpinnyStar extends Application { Pane pane = new Pane(); int width = 500; int height = 500; int cx = width / 2; //origin X int cy = height / 2; // origin y double rotate = 0; int r = 25; ArrayList hexagrams = new ArrayList(); @Override public void start(Stage stage) throws Exception { pane.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); if (hexagrams.size() == 0) { Hexagram hexagram = new Hexagram(r); hexagrams.add(hexagram); } EventHandler eventHandler = e -> { pane.getChildren().clear(); ArrayList hexList= (ArrayList) hexagrams.clone(); double circleSize = 5.0; for(Hexagram h : hexList) { Group g = new Group(); h.increaseRadius(); Point2D[] hexPoints = h.getPoints(); for(Point2D point : hexPoints) { double x = point.getX(); double y = point.getY(); Circle c = new Circle(x, y, circleSize, Color.AQUA); c.setEffect(new BoxBlur(2, 2, 3)); g.getChildren().add(c); } h.increaseRotation(); g.setRotate(h.getRotate()); pane.getChildren().add(g); //System.out.println(h.getRadius()); if(h.getRadius() == 50) { //System.out.println("New Hexagram"); Hexagram hexagram = new Hexagram(r); hexagrams.add(hexagram); } if(h.getRadius() > 1000) { hexagrams.remove(hexagrams.indexOf(h)); } } //r++; }; Timeline animation = new Timeline( new KeyFrame(Duration.millis(25), eventHandler)); animation.setCycleCount(Timeline.INDEFINITE); animation.play(); Scene scene = new Scene(pane, width, height); stage.setScene(scene); stage.setMaximized(true); stage.show(); } public static void main(String[] args) { launch(args); } class Hexagram extends Circle { Point2D[] points = new Point2D[36]; public Hexagram() { this(1.0); } public void increaseRotation() { double rotate = super.getRotate() == 360 ? 0 : super.getRotate()-0.4; super.setRotate(rotate); //updatePoints(); } public void increaseRadius() { double radius = super.getRadius(); super.setRadius(radius+0.5); updatePoints(); } private void updatePoints() { for (int i = 0; i < points.length; i++) { int angle = (360 / points.length) * i; double maths = angle % (360 / 6); maths = Math.abs(30 - maths); // distance from 45 degrees maths = super.getRadius() - (super.getRadius() * (maths/90) ); double X = cx + maths * Math.sin(Math.toRadians(angle)); double Y = cy + maths * Math.cos(Math.toRadians(angle)); //System.out.printf("Point %2d:\t%.2f,%.2f\n", i, X, Y); Point2D p = new Point2D(X, Y); points[i] = p; } } public Hexagram(double radius) { super(radius); //System.out.printf("Origin:\t(%2d,%-2d)\n", cx, cy); for (int i = 0; i < points.length; i++) { int angle = (360 / points.length) * i; double maths = angle % (360 / 6); maths = Math.abs(30 - maths); // distance from 45 degrees maths = super.getRadius() - (super.getRadius() * (maths/90) ); double X = cx + maths * Math.sin(Math.toRadians(angle)); double Y = cy + maths * Math.cos(Math.toRadians(angle)); //System.out.printf("Point %2d:\t%.2f,%.2f\n", i, X, Y); Point2D p = new Point2D(X, Y); points[i] = p; } } public Point2D[] getPoints() { return points; } } }