HTML canvas beginPath() 方法
實例
在畫布上繪製兩條路徑;綠色和紫色:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="green"; // Green path
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // Draw it
ctx.beginPath();
ctx.strokeStyle="purple"; // Purple path
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); // Draw it
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.lineWidth="5";
ctx.strokeStyle="green"; // Green path
ctx.moveTo(0,75);
ctx.lineTo(250,75);
ctx.stroke(); // Draw it
ctx.beginPath();
ctx.strokeStyle="purple"; // Purple path
ctx.moveTo(50,0);
ctx.lineTo(150,130);
ctx.stroke(); // Draw it
嘗試一下»
瀏覽器支持
Internet Explorer 9、Firefox、Opera、Chrome 和Safari 支持beginPath() 方法。
注意: Internet Explorer 8及之前的版本不支持<canvas>元素。
定義和用法
beginPath() 方法開始一條路徑,或重置當前的路徑。
提示:請使用這些方法來創建路徑moveTo()、lineTo()、quadricCurveTo()、bezierCurveTo()、arcTo()和arc()。
提示:請使用stroke()方法在畫布上繪製確切的路徑。
JavaScript 語法: | context.beginPath(); |
---|
HTML canvas參考手冊