首页 > 其他 > 详细

雨落青衫湿

时间:2014-07-24 23:12:13      阅读:444      评论:0      收藏:0      [点我收藏+]



<html>
    <head>
        <script type="text/javascript">
            function rain() {
                var canvas = document.getElementById( "sky" );
                var context = canvas.getContext( "2d" );
                var canvas_width = canvas.width;
                var canvas_height = canvas.height;
                var rain_start_interval_y = 100;
                var rain_size = 8;

                function ClassRain(){
                    this.size = rain_size * Math.random();
                    this.pos_x = canvas_width * Math.random();
                    this.pos_y = rain_start_interval_y * Math.random();
                    this.dy = 10 * Math.random();
                }

                function beginRain() {
                    context.fillStyle = "rgba(236, 240, 241, 0.65)";
                    context.fillRect( 0, 0, canvas_width, canvas_height );
                    context.fillStyle = "#95a5a6";

                    for( var i = 0; i < rains.length; ++i ){
                        var item = rains[i];
                        context.fillRect( item.pos_x, item.pos_y, item.size, item.size );
                        item.pos_y += item.dy;
                        if( item.pos_y > canvas_height ){
                            item.pos_y = -10;
                        }
                    }
                }
                var rains = [];
                for( var i = 0; i < 100; ++i ){
                    rains.push( new ClassRain() );
                }
                setInterval( beginRain, 25 )
            }
        </script>
    </head>

    <body onload="rain()">
        <canvas id="sky" width="800" height="400"></canvas>
    </body>
</html>


雨落青衫湿,布布扣,bubuko.com

雨落青衫湿

原文:http://blog.csdn.net/pandora_madara/article/details/38091625

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!