-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathRotating_Pattern_Animation_1020_pixels.java
More file actions
79 lines (67 loc) · 2.83 KB
/
Rotating_Pattern_Animation_1020_pixels.java
File metadata and controls
79 lines (67 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class RotatingPatternAnimation extends Application {
private static final int WIDTH = 1020;
private static final int HEIGHT = 1020;
private static final int BALL_RADIUS = 15;
private static final int CIRCLE_RADIUS = 480;
private static final int LINE_COUNT = 24;
private double angle = 0.0;
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, WIDTH, HEIGHT, Color.BLACK);
Circle baseCircle = new Circle(WIDTH / 2, HEIGHT / 2, CIRCLE_RADIUS, Color.BLACK);
root.getChildren().add(baseCircle);
for (int i = 0; i < LINE_COUNT; i++) {
double angle = (i / (double) LINE_COUNT) * 2 * Math.PI;
double x = WIDTH / 2 + CIRCLE_RADIUS * Math.cos(angle);
double y = HEIGHT / 2 + CIRCLE_RADIUS * Math.sin(angle);
Line line = new Line(WIDTH / 2, HEIGHT / 2, x, y);
line.setStroke(Color.WHITE);
root.getChildren().add(line);
}
AnimationTimer animationTimer = new AnimationTimer() {
@Override
public void handle(long now) {
root.getChildren().removeIf(node -> node instanceof Circle);
double circle = Math.PI * 2;
int length = 12;
int halfLength = length / 2;
double cx = 510;
double cy = 510;
double w = 450;
double h = 450;
for (int i = 0; i < length; i++) {
double a = (i / (double) length) * circle;
double x = cx + Math.round(Math.cos(a) * w);
double y = cy + Math.round(Math.sin(a) * h);
Circle ball = new Circle(x, y, BALL_RADIUS, Color.WHITE);
root.getChildren().add(ball);
if (i >= halfLength) {
double innerAngle = a + angle;
double rangeVal = Math.cos(innerAngle);
x = cx + Math.round(Math.cos(a) * (w - 1) * rangeVal);
y = cy + Math.round(Math.sin(a) * (h - 1) * rangeVal);
ball = new Circle(x, y, BALL_RADIUS, Color.WHITE);
root.getChildren().add(ball);
}
}
angle += 0.01;
}
};
animationTimer.start();
primaryStage.setTitle("Rotating Pattern");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}