javafx的练习五

package com.meyacom.first;

import static java.lang.Math.random;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
import javafx.util.Duration;
/***
 *
 * 类名:FivthDemo
 *
 * @author 朱湘鄂
 * @Created Date:2011-7-14 @Created Time:下午03:36:33
 * @Copyright  2011-2023 MYC Corporation, All Rights Reserved.
 * 这个实例是在第
 */
public class FivthDemo extends Application{


    /**
     * 方法用途:
     * 方法名称: main
     * @param args
     *     返回类型:void
     *     返回值说明:
     */
    public static void main(String[] args) {
            Application.launch(args);//这个方法是唯一在main方法里面调用的
    }

    @Override//重写start方法
    public void start(Stage arg0) throws Exception {
        Group root = new Group();//创建一个根节点
       
        Scene scene = new Scene(root,800,600,Color.BLUE);//背景的颜色
        arg0.setScene(scene);
       
        Group cycle = new Group();
        for(int i=0;i<30;i++){
            Circle circle = new Circle(150,Color.web("red",0.05));
            circle.setStrokeType(StrokeType.OUTSIDE);
            circle.setStroke(Color.web("white",0.16));
            circle.setStrokeWidth(4);
            cycle.getChildren().add(circle);
        }
        //cycle.setEffect(new BoxBlur(10,10,3));//添加模糊效果
       
        Rectangle colors = new Rectangle(scene.getWidth(),scene.getHeight(),//创建一个矩形的效果图
                new LinearGradient(0f,1f,1f,0f,true,CycleMethod.NO_CYCLE,new //从左下角0,0开始,在右下角1,1结束的一个线性填充
                        Stop[]{//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")),
                }));
        //root.getChildren().add(colors);//不添加渐变到容器root中
        //root.getChildren().add(cycle);//不将圆添加到背景中
       
        //应用混合模式
        //Group blendModeGroup = new Group(//创建混合模式
        //                new Group(new Rectangle(scene.getWidth(),scene.getHeight(),Color.BLACK),cycle),colors);//该混合模式包含两个子元素
        //第一个是一个匿名的Group,第二个是上面创建的那个cycle
        //blendModeGroup.setBlendMode(BlendMode.OVERLAY);//
        //root.getChildren().add(blendModeGroup);//添加blendModeGroup的场景图
       
        //添加动画,随机的移动
        Timeline timeline = new Timeline();
        for(Node circle:cycle.getChildren()){
            timeline.getKeyFrames().addAll(
                    new KeyFrame(Duration.ZERO,
                            new KeyValue(circle.translateXProperty(),random()*800),
                            new KeyValue(circle.translateYProperty(),random()*600)
                    ),
                    new KeyFrame(new Duration(40000),
                            new KeyValue(circle.translateXProperty(),random()*800),
                            new KeyValue(circle.translateYProperty(),random()*600)
                    )
            );
        }
        timeline.play();
        root.getChildren().add(colors);//不添加渐变到容器root中
        root.getChildren().add(cycle);//不将圆添加到背景中
        arg0.setVisible(true);//让stage可见
        arg0.setTitle("练习五--动画特效");
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值