p5实现雪花飞舞动画效果代码

代码语言:html

所属分类:粒子

代码描述:p5实现雪花飞舞动画效果代码

代码标签: 飞舞 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.0.10.2.js"></script>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>




</head>

<body>

    <script>
        let cnv;
        let snow = [];


        function setup() {
            cnv = createCanvas(windowWidth, windowHeight);
            cnv.position((windowWidth-width)/2, (windowHeight-height)/2);
            background(0);
            rectMode(CENTER);
            for (var i = 0; i < width*height/15000; i++) {
                snow.push(new snowflake());
            }
        }


        function draw() {
            background(0);
            for (var i = 0; i < snow.length; i++) {
                snow[i].update();
                snow[i].render();
                snow[i].reset();
            }
        }

        let snowflake = function() {
            this.posX = random(width);
            this.posY = random(height);
            this.rotation = random(PI/3);
            this.speed = random(.3, .8);
            this.rotateSpeed = (random()-.5)*this.speed/20;
            this.opacity = random(30, 90);
            this.size = random(5, 20).........完整代码请登录后点击上方下载按钮下载查看

网友评论0