JavaFX实现简单下雨动效

下雨动效可以使用JavaFX的动画功能来实现。下面是一个简单的示例代码,实现了一个下雨的动画效果:

import javafx.animation.Animation;
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.paint.Color;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.util.Random;

public class RainAnimation extends Application {

    private static final int WIDTH = 800;
    private static final int HEIGHT = 600;
    private static final int NUM_RAINDROPS = 100;

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Rain Animation");
        Group root = new Group();
        Random random = new Random();

        for (int i = 0; i < NUM_RAINDROPS; i++) {
            int startX = random.nextInt(WIDTH);
  

你可能感兴趣的:(javafx,javafx)