代碼如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>html5圓形</title> <script type="text/javascript"> window.addEventListener("load",function(){ //canvas的2d上下文 var ctx=document.getElementById("canvas").getContext("2d"); //圓1 ctx.beginPath(); ctx.arc(150,45,35,0,Math.PI*2,false); ctx.fillStyle="rgba(192,80,77,0.7)";//半透明的紅色 ctx.fill(); ctx.strokeStyle="rgba(192,80,77,1)";//紅色 ctx.stroke(); //圓2 ctx.beginPath(); ctx.arc(125,95,35,0,Math.PI*2,false); ctx.fillStyle="rgba(155,187,89,0.7)";//半透明綠色 ctx.fill(); ctx.strokeStyle="rgba(155,187,89,1)";//綠色 ctx.stroke(); //圓3 ctx.beginPath(); ctx.arc(175,95,35,Math.PI*2,false); ctx.fillStyle="rgba(128,100,162,0.7)";//半透明的紫色 ctx.fill(); ctx.strokeStyle="rgba(128,100,132,1)";//紫色 ctx.stroke(); }); </script> </head> <body> <canvas id="canvas" width="600" height="600"></canvas> </body> </html>
上圖是繪制的三個圓形相互折騰的,另外可以直接修改那個開始角度和結束弧度來畫弧線。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com