From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../canvasrenderingcontext2d/beginpath/index.html | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 files/ja/web/api/canvasrenderingcontext2d/beginpath/index.html (limited to 'files/ja/web/api/canvasrenderingcontext2d/beginpath') diff --git a/files/ja/web/api/canvasrenderingcontext2d/beginpath/index.html b/files/ja/web/api/canvasrenderingcontext2d/beginpath/index.html new file mode 100644 index 0000000000..b80da36304 --- /dev/null +++ b/files/ja/web/api/canvasrenderingcontext2d/beginpath/index.html @@ -0,0 +1,90 @@ +--- +title: CanvasRenderingContext2D.beginPath() +slug: Web/API/CanvasRenderingContext2D/beginPath +tags: + - API + - Canvas + - CanvasRenderingContext2D + - Method + - Reference +translation_of: Web/API/CanvasRenderingContext2D/beginPath +--- +
{{APIRef}}
+ +

Canvas 2D API のCanvasRenderingContext2D.beginPath() メソッドは、サブパスのリストを空にすることにより新しいパスを開始します。新しいパスを作成したい場合、このメソッドを呼び出してください。

+ +
+

注: 新しいサブパス (つまり、現在のキャンバスの状態に一致するサブパス) を作成する場合、{{domxref("CanvasRenderingContext2D.moveTo()")}}を使用できます。

+
+ +

構文

+ +
void ctx.beginPath();
+
+ +

+ +

異なるパスの作成

+ +

この例では、それぞれが1本の直線を含む2つのパスを作成します。

+ +

HTML

+ +
<canvas id="canvas"></canvas>
+
+ +

JavaScript

+ +

beginPath() メソッドはそれぞれの線についての処理開始前に呼ばれるため、各線は別々の色で描かれるでしょう。

+ +
const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+
+// 第1のパス
+ctx.beginPath();
+ctx.strokeStyle = 'blue';
+ctx.moveTo(20, 20);
+ctx.lineTo(200, 20);
+ctx.stroke();
+
+// 第2のパス
+ctx.beginPath();
+ctx.strokeStyle = 'green';
+ctx.moveTo(20, 20);
+ctx.lineTo(120, 120);
+ctx.stroke();
+
+ +

実行結果

+ +

{{ EmbedLiveSample('Creating_distinct_paths', 700, 180) }}

+ +

仕様

+ + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-beginpath", "CanvasRenderingContext2D.beginPath")}}{{Spec2('HTML WHATWG')}} 
+ +

ブラウザー実装状況

+ + + +

{{Compat("api.CanvasRenderingContext2D.beginPath")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf