茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    用HTML5制作煙火效果的教程
    來源:易賢網(wǎng) 閱讀:1410 次 日期:2016-07-09 11:13:58
    溫馨提示:易賢網(wǎng)小編為您整理了“用HTML5制作煙火效果的教程”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了用HTML5制作煙火效果的教程,主要利用到了Canvas API,需要的朋友可以參考下

    原理很簡單。。。就寫一個煙火類以及碎屑類,實例化后讓它飛起來,然后到達某個點后,把這個煙火對象的dead屬性置為true,然后再實例化出一定數(shù)量的碎屑對象,并且給與碎屑對象隨機一個要到達的目標點,然后讓所有碎屑對象飛過去就行了。

    【煙火】

    XML/HTML Code

    var Boom = function(x,r,c,boomArea,shape){  //煙火對象   

                this.booms = [];   

                this.x = x;   

                this.y = (canvas.height+r);   

                this.r = r;   

                this.c = c;   

                this.shape = shape || false;   

                this.boomArea = boomArea;   

                this.theta = 0;   

                this.dead = false;   

                this.ba = parseInt(getRandom(80 , 200));   

            }   

            Boom.prototype = {   

                _paint:function(){     

                    ctx.save();   

                    ctx.beginPath();   

                    ctx.arc(this.x,this.y,this.r,0,2*Math.PI);   

                    ctx.fillStyle = this.c;   

                    ctx.fill();   

                    ctx.restore();   

                },   

                _move:function(){   

                    var dx = this.boomArea.x - this.x , dy = this.boomArea.y - this.y;   

                    thisthis.x = this.x+dx*0.01;   

                    thisthis.y = this.y+dy*0.01;   

                    if(Math.abs(dx)<=this.ba && Math.abs(dy)<=this.ba){   

                        if(this.shape){   

                            this._shapBoom();   

                        }   

                        else this._boom();   

                        this.dead = true;   

                    }   

                    else {   

                        this._paint();   

                    }   

                },   

                _drawLight:function(){   

                    ctx.save();   

                    ctx.fillStyle = "rgba(255,228,150,0.3)";   

                    ctx.beginPath();   

                    ctx.arc(this.x , this.y , this.r+3*Math.random()+1 , 0 , 2*Math.PI);   

                    ctx.fill();   

                    ctx.restore();   

                },   

                _boom:function(){    //普通爆炸   

                    var fragNum = getRandom(30 , 200);   

                    var style = getRandom(0,10)>=5? 1 : 2;   

                    var color;   

                    if(style===1){   

                        color = {   

                            a:parseInt(getRandom(128,255)),   

                            b:parseInt(getRandom(128,255)),   

                            c:parseInt(getRandom(128,255))   

                        }   

                    }   

                    var fanwei = parseInt(getRandom(300, 400));   

                    for(var i=0;i<fragNum;i++){   

                        if(style===2){   

                            color = {   

                                a:parseInt(getRandom(128,255)),   

                                b:parseInt(getRandom(128,255)),   

                                c:parseInt(getRandom(128,255))   

                            }   

                        }   

                        var a = getRandom(-Math.PI, Math.PI);   

                        var x = getRandom(0, fanwei) * Math.cos(a) + this.x;   

                        var y = getRandom(0, fanwei) * Math.sin(a) + this.y;    

                        var radius = getRandom(0 , 2)   

                        var frag = new Frag(this.x , this.y , radius , color , x , y );   

                        this.booms.push(frag);   

                    }   

                },   

                _shapBoom:function(){    //有形狀的爆炸   

                    var that = this;   

                    putValue(ocas , octx , this.shape , 5, function(dots){   

                        var dx = canvas.width/2-that.x;   

                        var dy = canvas.height/2-that.y;   

                        for(var i=0;i<dots.length;i++){   

                            color = {a:dots[i].a,b:dots[i].b,c:dots[i].c}   

                            var x = dots[i].x;   

                            var y = dots[i].y;   

                            var radius = 1;   

                            var frag = new Frag(that.x , that.y , radius , color , x-dx , y-dy);   

                            that.booms.push(frag);   

                        }   

                    })   

                }   

            }   

    【碎屑】

    XML/HTML Code

    var Frag = function(centerX , centerY , radius , color ,tx , ty){   //煙火碎屑對象   

                this.tx = tx;   

                this.ty = ty;   

                this.x = centerX;   

                this.y = centerY;   

                this.dead = false;   

                this.centerX = centerX;   

                this.centerY = centerY;   

                this.radius = radius;   

                this.color = color;   

            }   

            Frag.prototype = {   

                paint:function(){   

                    ctx.save();   

                    ctx.beginPath();   

                    ctx.arc(this.x , this.y , this.radius , 0 , 2*Math.PI);   

                    ctx.fillStyle = "rgba("+this.color.a+","+this.color.b+","+this.color.c+",1)";   

                    ctx.fill()   

                    ctx.restore();   

                },   

                moveTo:function(index){   

                    thisthis.ty = this.ty+0.3;   

                    var dx = this.tx - this.x , dy = this.ty - this.y;   

                    this.x = Math.abs(dx)<0.1 ? this.tx : (this.x+dx*0.1);   

                    this.y = Math.abs(dy)<0.1 ? this.ty : (this.y+dy*0.1);   

                    if(dx===0 && Math.abs(dy)<=80){   

                        this.dead = true;   

                    }   

                    this.paint();   

                }   

            }  

    讓碎屑產(chǎn)生虛影也很簡單,就是每次刷新畫布時,不是擦掉重繪,而是繪制透明度為0.1(如果想虛影更長,可以把這個值弄的更?。┑谋尘邦伾H缓筇撚熬涂梢宰龀鰜砹?。也就是:

    XML/HTML Code

    ctx.save();   

                ctx.fillStyle = "rgba(0,5,24,0.1)";   

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

                ctx.restore();  

    讓煙火形成自己想要的形狀,比如字體,圖片之類的,也很簡單,就是可以通過離屏canvas以及canvas的getImageData這個方法就可以做出來。離屏canvas,顧名思義就是離開屏幕的,也就是不可見的canvas,直接在js里面用document.createElement("canvas")就可以生成一個canvas dom對象了,只要不把這個dom對象賦給body,這個canvas對象就相當于一個離屏對象了,我們就可以獲取到這個離屏canvas的context對象,然后再用戶看不到的地方做任何我們想做的事情了。

    讓煙火形成自己想要的形狀就是先把文字或者圖片畫在離屏canvas上,然后用getImageData獲取畫布上的像素數(shù)組,然后遍歷數(shù)組,獲取有顏色的像素,也就是我們想要的內(nèi)容,保存起來后,再放到主canvas對象中顯示出來。

    更多信息請查看網(wǎng)頁制作
    易賢網(wǎng)手機網(wǎng)站地址:用HTML5制作煙火效果的教程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇剩?/div>

    2026國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)