<noscript id="eassg"><table id="eassg"></table></noscript>
  • <strike id="eassg"><s id="eassg"></s></strike>
  • <ul id="eassg"></ul>
    注冊|登錄

    聯(lián)系電話:024-31891684  13390130939
    沈陽軟件公司--沈陽軟件定制

    沈陽軟件開發(fā)_沈陽軟件公司_沈陽軟件定制/軟件/最新技術(shù)

    Latest technology最新技術(shù)

    canvas通過動態(tài)生成像素點做絢麗效果

    瀏覽量:3311

    本例中的粒子就是實實在在的像素,由js代碼在canvas上動態(tài)生成的像素點!這些像素點通過一個運動方法有規(guī)律地動了起來。

    <!doctype html>

    <html>

    <head>

        <title>智能粒子</title>

        <meta charset='utf-8' />

        <style type="text/css">

            body{background-color:black;}

            #Canvas{margin:50px auto;display:block;border:1px red solid;}

        </style>

    </head>

     

    <body>

        <canvas width='300' height='300' id='Canvas'>您的瀏覽器不支持canvas</canvas>

    </body>

    <script type="text/javascript">

        /*

         *用面向?qū)ο缶幊谭椒▽崿F(xiàn)的粒子

         *by @謝帥shawn

         */

        //初始化畫布

        varcanvas=document.getElementById('Canvas');

        varctx=canvas.getContext('2d');

       

        /*

         *創(chuàng)建一個圓環(huán)類Circle,智能圓環(huán)的模型

         */

        varCircle=function(x,y,speeds){

            this.x=x;

            this.y=y;

            this.speed=speeds;

        }

        Circle.prototype={

            //draw方法,畫出像素

            draw:function(){   

               

                varn=this.y*imgdata.width+this.x;

                vari=n*4;

                data[i]+=207;

                data[i+1]+=14;

                data[i+2]+=139;

                data[i+3]+=150;

            },

            //move方法,圓環(huán)坐標自加速度,并執(zhí)行draw方法

            move:function(){

                this.x+=this.speed.speedX;

                this.y+=this.speed.speedY;

                this.draw();

            }

        }

        /*

         *創(chuàng)建一個Frame幀類,管理所有circles實例,實現(xiàn)畫布的渲染

         */

        varFrame=function(){

            this.circles=[];

            this.sint=null;

        }

        Frame.prototype={

            //star開始定時器,循環(huán)調(diào)用渲染方法

            star:function() {

                this.lastFrame=(newDate()).getTime();

                this.sint=setInterval((function(progra){

                    returnfunction(){progra.render();}

                })(this),30);   

            },

            //render渲染方法

            render:function() {

                //清除上一幀

                ctx.clearRect(0,0,canvas.width,canvas.height);

                imgdata=ctx.getImageData(0,0,canvas.width,canvas.height);

                data=imgdata.data;

                //實時輸出幀率

                this.nowFrame=(newDate()).getTime();

                this.ftp=1000/(this.nowFrame-this.lastFrame);

                this.lastFrame=this.nowFrame;

                console.log(this.ftp);

                //調(diào)用每個實例circle的運動方法,監(jiān)聽circle坐標實現(xiàn)碰壁反彈效果

                for(i inthis.circles) {

                    this.circles[i].move();

                    if(this.circles[i].x>canvas.width ||this.circles[i].x<0){

                        this.circles[i].speed.speedX=-this.circles[i].speed.speedX;

                        //delete this.circles[i];可以實現(xiàn)碰壁消失的效果,delete可刪除實例

                    }

                    if(this.circles[i].y>canvas.height||this.circles[i].y<0)

                        this.circles[i].speed.speedY=-this.circles[i].speed.speedY;

     

                }

                ctx.putImageData(imgdata,0,0);

            }   

        }

        /*

         *Main

         */

        //創(chuàng)建一個幀實例fra

        varfra=newFrame();

        //創(chuàng)建100個圓環(huán)實例circles【i】

        for(vari=0; i<20000; i++) {

            //輸入speed屬性

            varspeed={

                speedX:Math.floor(Math.random()*3),

                speedY:Math.floor(Math.random()*10+4)

            }

            //創(chuàng)建實例

            varcircle=newCircle(Math.floor(Math.random()*canvas.width/2),Math.floor(Math.random()*canvas.height/2),speed);

            fra.circles[i]=circle;

        }

        //開始渲染

        fra.star();

    </script>

    </html>

    沈陽團購網(wǎng)|營口網(wǎng)站制作|沈陽軟件公司|軟件定制|網(wǎng)站建設(shè)|加盟易勢|提交問題

    日韩AV片无码一区二区不卡| 亚洲国产精品线观看不卡| 精品乱码一区二区三区在线| 思思91精品国产综合在线| 国产精品大全国产精品| 中文字幕日韩精品麻豆系列| 久久夜色精品国产噜噜| 精品一区二区三区免费| 99re热这里只有精品视频中文字幕| 亚洲国产精品综合久久一线| 日韩精品中文字幕无码专区| 99热门精品一区二区三区无码| 精品国产福利第一区二区三区 | 一本色道久久88综合日韩精品| 中日韩美中文字幕| 国产精品成人亚洲| 国产精品美女久久久久av超清| 青青青亚洲精品国产| 成人区人妻精品一区二区不卡| 精品国产麻豆免费网站| 欧美成人aaa片一区国产精品| 四虎永久在线观看视频精品| 91一区二区在线观看精品| 亚洲一区精品中文字幕| 日韩精品无码熟人妻视频| 无码国产精品一区二区免费3p| 无码精品国产VA在线观看| 日韩精品系列产品| 乱色精品无码一区二区国产盗| 久久久国产精品亚洲一区| 久久久久亚洲精品天堂| 99热这里只/这里有精品| 91热久久免费精品99| 久久精品国产久精国产果冻传媒| 精品久久亚洲中文无码| 国产69精品久久久久777| 四虎亚洲精品高清在线观看| 亚洲国产精品无码久久98| 精品国产自在现线久久| 国产精品久久久尹人香蕉| 日韩一区二区三区在线观看|