Java Reference
In-Depth Information
Group circles = new Group();
for (int i = 0; i < 500; i++) {
Circle circle = new Circle(30, Color.web("black", 0.10));
circle.setStrokeType(StrokeType.OUTSIDE);
circle.setStroke(Color.web("black", 0.15));
circle.setStrokeWidth(2);
circles.getChildren().add(circle);
}
Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),
new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.REPEAT,
new Stop[]{
new Stop(0, Color.web("#f8bd55")),
new Stop(0.14, Color.web("#c0fe56")),
new Stop(0.28, Color.web("#5dfbc1")),
new Stop(0.43, Color.web("#64c2f8")),
new Stop(0.57, Color.web("#be4af7")),
new Stop(0.71, Color.web("#ed5fc2")),
new Stop(0.85, Color.web("#ef504c")),
new Stop(1, Color.web("#f2660f"))}
));
colors.widthProperty().bind(scene.widthProperty());
colors.heightProperty().bind(scene.heightProperty());
Group blendModeGroup = new Group(
new Group(
new Rectangle(scene.getWidth(), scene.getHeight(),
Color.WHITE), circles), colors);
colors.setBlendMode(BlendMode.OVERLAY);
root.getChildren().add(blendModeGroup);
circles.setEffect(new BoxBlur(10, 10, 3));
Timeline timeline = new Timeline();
for (Node circle : circles.getChildren()) {
timeline.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO,
new KeyValue(circle.translateXProperty(),
random() * scene.getWidth()),
new KeyValue(circle.translateYProperty(),
random() * scene.getHeight())),
new KeyFrame(new Duration(60000),
new KeyValue(circle.translateXProperty(),
random() * scene.getWidth()),
new KeyValue(circle.translateYProperty(),
random() * scene.getHeight())));
}
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
primaryStage.show();
}
}
Feel free to daydream while JavaFX shows its graphical prowess in Figure 11-35.
Search WWH ::




Custom Search