标签:idt bsp red cti png oct draw 案例 context
需要使用: ctx.fillStyle().
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id="canv" width="300" height="300"></canvas> <script> function draw() { var canvas = document.getElementById(‘canv‘); if (!canvas.getContext) return; var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.arc(150, 150, 50, 0, -Math.PI/2, true); ctx.fillStyle = "red"; ctx.fill(); ctx.beginPath(); ctx.arc(150, 150, 50, -Math.PI/2, -Math.PI, true); ctx.fillStyle = "green"; ctx.fill(); ctx.beginPath(); ctx.arc(150, 150, 50, -Math.PI, -Math.PI*3/2, true); ctx.fillStyle = "orange"; ctx.fill(); ctx.beginPath(); ctx.arc(150, 150, 50, -Math.PI*3/2, -Math.PI*2, true); ctx.fillStyle = "blue"; ctx.fill(); } draw(); </script> </body> </html>
注意:
1. 如果当前Path没有闭合, 则 ctx.fill() 会先闭合再填充;
2. 案例中使用了四次ctx.beginPath(), 说明这个图形下了四笔.
标签:idt bsp red cti png oct draw 案例 context
原文地址:https://www.cnblogs.com/aisowe/p/11572307.html