2.6_路径描边与填充
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>路径描边与填充</title>
<style>
body{
background: #000000;
}
#canvas{
background: #fff;
}
</style>
</head>
<body>
<canvas id="canvas" width="1100" height="650"></canvas>
</body>
<script>
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
context.font = '48pt Helvetica';
context.strokeStyle = 'blue';
context.fillStyle = 'red';
context.lineWidth = '2';
context.strokeText('stroke',60,110);
context.fillText('Fill',440,110);
context.strokeText('Stroke&Fill',650,110);
context.fillText('Stroke&Fill',650,110);
context.lineWidth = '5';
context.beginPath();
context.rect(80,150,150,100);
context.stroke();
context.beginPath();
context.rect(400,150,150,100);
context.fill();
context.beginPath();
context.rect(750,150,150,100);
context.fill();
context.stroke();
context.beginPath();
context.arc(150,370,60,0,Math.PI*3/2);
context.stroke();
context.beginPath();
context.arc(475,370,60,0,Math.PI*3/2);
context.fill();
context.beginPath();
context.arc(820,370,60,0,Math.PI*3/2);
context.stroke();
context.fill();
context.beginPath();
context.arc(150,550,60,0,Math.PI*3/2);
context.closePath();
context.stroke();
context.beginPath();
context.arc(475,550,60,0,Math.PI*3/2);
context.closePath();
context.fill();
context.beginPath();
context.arc(820,550,60,0,Math.PI*3/2);
context.closePath();
context.stroke();
context.fill();
</script>
</html>