Dream Night is a famous screen saver. It can be seen on old S40 Nokia mobile sets. It was my favorite screen saver. This is very easy to implement in JavaFX.
The screen shot of Dream Night animation is bellow. I hope you will remember it...
The screen shot of Dream Night animation is bellow. I hope you will remember it...
Video Tutorial
The source code of Dream Night Animation
import java.util.Random; import javafx.animation.FadeTransition; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Duration; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ http://gpusmackers.blogspot.in ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public class JavaFX_23 extends Application { Group cir = new Group(); @Override public void start(Stage stage) { AnchorPane root = new AnchorPane(); Random rand = new Random(); for(int i=0;i<50;i++) { int r = rand.nextInt(255); int g = rand.nextInt(255); int b = rand.nextInt(255); Circle c = new Circle(0.1, Color.rgb(r, g, b, 0.5)); c.setCenterX(rand.nextInt(800)); c.setCenterY(rand.nextInt(500)); Timeline t = new Timeline(); t.setCycleCount(Timeline.INDEFINITE); Duration d = Duration.seconds(rand.nextInt(30)+15); KeyValue kv = new KeyValue(c.radiusProperty(), rand.nextInt(100)); KeyFrame kf = new KeyFrame(d, kv); t.getKeyFrames().add(kf); cir.getChildren().add(c); t.play(); } root.getChildren().add(cir); Scene scene = new Scene(root, 800, 500, Color.BLACK); stage.setScene(scene); stage.setTitle("Dream Night Animation in JavaFX"); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }
No comments:
Post a Comment