Capítulo 4

Canvas - Exemplo 10: path método fill().

Conteúdo alternativo para navegadores que não suportam canvas.

JavaScript

<script>
window.onload = function() {
var canvas = document.getElementById('quadro');
var ctx = canvas.getContext('2d'); 
	
	ctx.lineWidth = 4;
	
	ctx.beginPath();
	ctx.strokeStyle = '#f00';
	ctx.fillStyle = '#0ff';
	ctx.arc(80, 100, 40, 0, Math.PI*2, true);
	ctx.fill();
	ctx.stroke();
	
	ctx.beginPath();
	ctx.strokeStyle = '#090';
	ctx.fillStyle = '#996';
	ctx.arc(200, 100, 40, 0, Math.PI, true);
	ctx.fill();
	ctx.stroke();

	ctx.beginPath();
	ctx.strokeStyle = '#00f';
	ctx.fillStyle = '#c6c';
	ctx.arc(200, 100, 40, 0, Math.PI, false);
	ctx.fill();
	ctx.stroke();

	ctx.beginPath();
	ctx.strokeStyle = '#f90';
	ctx.fillStyle = '#0c0';
	ctx.arc(320, 100, 40, 0, 3/4*Math.PI, true);
	ctx.fill();
	ctx.stroke();
}
</script>

CSS

	canvas {border:1px solid #ccc;}

HTML

	<canvas id="quadro" width="400" height="200">
		<p>Conteúdo alternativo para navegadores que não suportam canvas.</p>
	</canvas>