效果圖展示:
canvas有些地方還是有點(diǎn)坑的,比如fillRect是方法不是屬性,如果寫(xiě)成fillRect=這樣是沒(méi)效果的,而且還不報(bào)錯(cuò)....
這里用到了createRadialGradient這個(gè)API 這個(gè)API接收6個(gè)參數(shù),前三個(gè)表示底下的圓,后三個(gè)表示上面的圓,返回的實(shí)例依然可以用addColorStop
can2_context是getContext的canvas繪圖上下文環(huán)境
function Radia(bottom_x,bottom_y,bottom_r,top_x,top_y,top_r){ this.bottom_x=bottom_x; this.bottom_y=bottom_y; this.bottom_r=bottom_r; this.top_x=top_x; this.top_y=top_y; this.top_r=top_r; this.gradient=can2_context.createRadialGradient(this.bottom_x,this.bottom_y,this.bottom_r,this.top_x,this.top_y,this.top_r) } Radia.prototype.addColor=function(){ for(var i=0;i<arguments.length;i++){ this.gradient.addColorStop(arguments[i].num,arguments[i].color) } } Radia.prototype.draw=function(x1,y1,x2,y2){ can2_context.fillStyle=this.gradient; can2_context.fillRect(x1,y1,x2,y2) } var some1=new Radia(canvas_2.width/2, canvas_2.height-100, 0, canvas_2.width/2, 0, 300) some1.addColor({num:0.2,color:"blue"},{num:1,color:"yellow"},{num:0.7,color:"white"}) some1.draw(0, 0, canvas_2.width, canvas_2.height)
總結(jié)
以上所述是小編給大家介紹的html5 canvas繪制放射性漸變色效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
標(biāo)簽:紅河 甘南 文山 萍鄉(xiāng) 咸陽(yáng) 惠州 營(yíng)口 蘇州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《html5 canvas繪制放射性漸變色效果》,本文關(guān)鍵詞 html5,canvas,繪制,放射性,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。