-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFXSandbox.java
More file actions
63 lines (53 loc) · 1.63 KB
/
Copy pathFXSandbox.java
File metadata and controls
63 lines (53 loc) · 1.63 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
package application;
import java.util.Random;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class FXSandbox extends Application
{
private static final int STAR_COUNT = 20000;
private final Rectangle[] nodes = new Rectangle[STAR_COUNT];
private final double[] angles = new double[STAR_COUNT];
private final long[] start = new long[STAR_COUNT];
private final Random random = new Random();
@Override
public void start(final Stage primaryStage)
{
for(int i = 0; i < STAR_COUNT; i++)
{
nodes[i] = new Rectangle(1, 1, Color.WHITE);
angles[i] = 2.0 * Math.PI * random.nextDouble();
start[i] = random.nextInt(2000000000);
}
final Scene scene = new Scene(new Group(nodes), 800, 600, Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
new AnimationTimer(){
@Override
public void handle(long now)
{
final double width = 0.5 * primaryStage.getWidth();
final double height = 0.5 * primaryStage.getHeight();
final double radius = Math.sqrt(2) * Math.max(width, height);
for(int i = 0; i < STAR_COUNT; i++)
{
final Node node = nodes[i];
final double angle = angles[i];
final long t = (now - start[i]) % 2000000000;
final double d = t * radius / 2000000000.0;
node.setTranslateX(Math.cos(angle) * d + width);
node.setTranslateY(Math.sin(angle) * d + height);
}
}
}.start();
}
public static void main(String[] args)
{
launch(args);
}
}