夏天快到了,热不热?下雪啦

夏天快到了,热不热?下雪啦

先看看我的另一篇文章:https://blog.csdn.net/WJW_harrypotter/article/details/129330879?spm=1001.2014.3001.5501

步骤:将下面的代码原封不动的输送进去

<head>
 
    <meta charset="UTF-8">
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
 
    <title>下雪啦</title>
 
    <!-- <script src="lib.js"></script> -->
 
    <style>
 
        * {
 
            margin: 0;
 
            padding: 0;
 
        }
 
 
 
        body {
 
            overflow: hidden;
 
        }
 
    </style>
 
</head>
 
 
 
<body>
 
    <script>
 
        window.onload = function () {
 
            var Canvas = function (w, h) {
 
                this.width = w;
 
                this.height = h;
 
            }
 
            Canvas.prototype = {
 
                init: function () {
 
                    var oC = document.createElement("canvas");
 
                    oC.setAttribute('width', this.width);
 
                    oC.setAttribute('height', this.height);
 
                    oC.setAttribute('id', 'canvas');
 
                    oC.style.backgroundColor = '#000';
 
                    document.body.appendChild(oC);
 
                }
 
            }
 
            var curWinWidth = window.innerWidth,
 
                curWinHeight = window.innerHeight;
 
            var oCanvas = new Canvas(curWinWidth, curWinHeight);
 
            oCanvas.init();
 
 
 
            var oC = document.querySelector('#canvas');
 
            var width = oC.width, height = oC.height, oGc = oC.getContext('2d');
 
 
 
            function random(min, max) {
 
                return Math.random() * (max - min) + min;
 
            }
 
            var Snow = function () {
 
 
 
            }
 
            Snow.prototype = {
 
                init: function () {
 
                    this.x = random(0, width);
 
                    this.y = 0;
 
                    this.r = random(1, 5);
 
                    this.vy = random(3, 5);
 
                },
 
                draw: function (cxt) {
 
                    cxt.beginPath();
 
                    cxt.fillStyle = 'white';
 
                    cxt.arc(this.x, this.y + this.r, this.r, 0, Math.PI * 2, false);
 
                    cxt.fill();
 
                    cxt.closePath();
 
                    this.update(cxt);
 
                },
 
                update: function (cxt) {
 
                    if (this.y < height - this.r) {
 
                        this.y += this.vy;
 
                    } else {
 
                        this.init();
 
                    }
 
                }
 
            }
 
 
 
            var snow = [];
 
            for (var i = 0; i < 500; i++) {
 
                setTimeout(function () {
 
                    var oSnow = new Snow();
 
                    oSnow.init();
 
                    snow.push(oSnow);
 
                }, 10 * i);
 
            }
 
 
 
            (function move() {
 
                oGc.clearRect(0, 0, width, height);
 
                for (var i = 0; i < snow.length; i++) {
 
                    snow[i].draw(oGc);
 
                }
 
                requestAnimationFrame(move);
 
            })();
 
        }
 
    </script>
 
</body>

搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值