您好,登錄后才能下訂單哦!
本文實例為大家分享了canvas實現簡單圖像擴散的代碼,供大家參考,具體內容如下
<!DOCTYPE HTML> <html> <body> <canvas id="myCanvas" width="800" height="800" > Your browser does not support the canvas element. </canvas> <script type="text/javascript"> var c=document.getElementById("myCanvas"); var cxt=c.getContext("2d"); var x1=200,x2=400,x3=600,y1=400,y2=400,y3=400,lr1=10,lr2=10,lr3=10; var lc1="#EE7942";lc2="#EE2C2C";lc3="#CD6839"; var lr1,lr2,lr3; drawarc(15,"#CAE1FF",1); drawarc(25,"#98FB98",2); drawarc(25,"#757575",3); drawarc(30,"#000000",1); drawarc(35,"#32CD32",2); drawarc(50,"#6959CD",3); drawarc(45,"red",1); drawarc(50,"#fff",2); drawarc(65,"#000",3); function drawarc(radiu,ecolor,type){ var grd; var x,y,r; var scolor; switch(type){ case 1: x=x1; y=y1; r=lr1; lr1=radiu; scolor=lc1; break; case 2: x=x2; y=y2; r=lr2; lr2=radiu; scolor=lc2; break; case 3: x=x3; y=y3; r=lr3; lr3=radiu; scolor=lc3; break; default: } grd=cxt.createRadialGradient(x,y,r,x,y,radiu); grd.addColorStop(0,scolor); grd.addColorStop(1,ecolor); cxt.fillStyle=grd; cxt.beginPath(); cxt.arc(x,y,radiu,0,360,false); cxt.closePath(); cxt.fill(); } </script> </body> </html>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。