效果如下:
代码如下:
<!DOCTYPE html>
<htmls>
<head>
<meta charset="UTF-8">
<title>Text2画圆</title>
</head>
<style>
</style>
<body>
<div id="canvas-warp">
<canvas id="canvas" style="border: 1px solid #aaaaaa; display: block; margin: 50px auto;">
1
</canvas>
</div>
<script>
window.onload = function () {
var canvas = document.getElementById("canvas");
canvas.width = 500;
canvas.height = 500;
var context = canvas.getContext("2d");
context.beginPath();
context.arc(100,70,50,0.5*Math.PI,1*Math.PI);
context.strokeStyle = "green";
context.fillStyle = "white";
context.fill(); //确认填充
context.lineWidth = 5
context.stroke();
context.beginPath();
context.arc(100,70,50,1*Math.PI,1.5*Math.PI);
context.strokeStyle = "#999";
context.fillStyle = "white";
context.fill(); //确认填充
context.stroke();
context.beginPath();
context.arc(100,70,50,1.5*Math.PI,2*Math.PI);
context.strokeStyle = "red";
context.fillStyle = "white";
context.fill(); //确认填充
context.stroke();
context.beginPath();
context.arc(100,70,50,2*Math.PI,0.5*Math.PI);
context.strokeStyle = "blue";
context.fillStyle = "white";
context.fill(); //确认填充
context.stroke();
}
</script>
</body>
</html>