From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/path2d/addpath/index.html | 131 +++++++++++++++++++++++++++ files/ja/web/api/path2d/index.html | 139 +++++++++++++++++++++++++++++ files/ja/web/api/path2d/path2d/index.html | 109 ++++++++++++++++++++++ 3 files changed, 379 insertions(+) create mode 100644 files/ja/web/api/path2d/addpath/index.html create mode 100644 files/ja/web/api/path2d/index.html create mode 100644 files/ja/web/api/path2d/path2d/index.html (limited to 'files/ja/web/api/path2d') diff --git a/files/ja/web/api/path2d/addpath/index.html b/files/ja/web/api/path2d/addpath/index.html new file mode 100644 index 0000000000..8cbf67ef2f --- /dev/null +++ b/files/ja/web/api/path2d/addpath/index.html @@ -0,0 +1,131 @@ +--- +title: Path2D.addPath() +slug: Web/API/Path2D/addPath +translation_of: Web/API/Path2D/addPath +--- +
{{APIRef("Canvas API")}}
+ +

Canvas 2D APIのPath2D.addPath()メソッドは、パスに対して引数でパスを追加します。

+ +

構文

+ +
void path.addPath(path [, transform]);
+
+ +

パラメーター

+ +
+
path
+
追加する{{domxref("Path2D")}}パス
+
transform {{optional_inline}}
+
パスに追加する変換マトリックスとして使われる{{domxref("SVGMatrix")}}.
+
+ +

+ +

addPathメソッドを使用する

+ +

これはaddPathメソッドを使用する簡単なコードスニペットです。

+ +
var canvas = document.getElementById("canvas");
+var ctx = canvas.getContext("2d");
+
+// rectで新しいパスを作成する
+var p1 = new Path2D();
+p1.rect(0,0,100,100);
+
+// rectで別のパスを作成する
+var p2 = new Path2D();
+p2.rect(0,0,100,100);
+
+// 右に縦300ポイント移動する変換マトリックスを作成する
+var m = document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGMatrix();
+m.a = 1; m.b = 0;
+m.c = 0; m.d = 1;
+m.e = 300; m.f = 0;
+
+// 2番目のパスを最初のパスに追加する
+p1.addPath(p2, m);
+
+// 最後に、1番目のパスをキャンバスに描画する
+ctx.fill(p1);
+
+ +

以下のコードを編集して、その変更が canvas に反映されることを確かめてください(現在のブラウザーが実際にこのメソッドをサポートしているか、以下のブラウザー互換テーブルをチェックしてください)

+ +

{{ EmbedLiveSample('Playable_code', 700, 500) }}

+ +

仕様

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', "scripting.html#dom-path2d-addpath", "Path2D.addPath()")}}{{Spec2('HTML WHATWG')}}初期定義
+ +

ブラウザー互換性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatNo}}{{CompatGeckoDesktop(34)}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile(34)}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +

関連情報

+ + diff --git a/files/ja/web/api/path2d/index.html b/files/ja/web/api/path2d/index.html new file mode 100644 index 0000000000..2048feff2e --- /dev/null +++ b/files/ja/web/api/path2d/index.html @@ -0,0 +1,139 @@ +--- +title: Path2D +slug: Web/API/Path2D +tags: + - API + - Canvas + - Interface + - NeedsTranslation + - Path2D + - Reference + - TopicStub +translation_of: Web/API/Path2D +--- +
{{APIRef("Canvas API")}} {{SeeCompatTable}}
+ +

The Path2D interface of the Canvas 2D API is used to declare paths that are then later used on {{domxref("CanvasRenderingContext2D")}} objects. The path methods of the CanvasRenderingContext2D interface are present on this interface as well and are allowing you to create paths that you can retain and replay as required on a canvas.

+ +

Constructors

+ +
+
{{domxref("Path2D.Path2D", "Path2D()")}}
+
Path2D constructor. Creates a new Path2D object.
+
+ +

Methods

+ +
+
{{domxref("Path2D.addPath()")}}
+
Adds a path to the current path.
+
{{domxref("CanvasRenderingContext2D.closePath", "Path2D.closePath()")}}
+
Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.
+
{{domxref("CanvasRenderingContext2D.moveTo()", "Path2D.moveTo()")}}
+
Moves the starting point of a new sub-path to the (x, y) coordinates.
+
{{domxref("CanvasRenderingContext2D.lineTo()", "Path2D.lineTo()")}}
+
Connects the last point in the subpath to the x, y coordinates with a straight line.
+
{{domxref("CanvasRenderingContext2D.bezierCurveTo()", "Path2D.bezierCurveTo()")}}
+
Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using moveTo() before creating the Bézier curve.
+
{{domxref("CanvasRenderingContext2D.quadraticCurveTo()", "Path2D.quadraticCurveTo()")}}
+
Adds a quadratic Bézier curve to the current path.
+
{{domxref("CanvasRenderingContext2D.arc()", "Path2D.arc()")}}
+
Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
+
{{domxref("CanvasRenderingContext2D.arcTo()", "Path2D.arcTo()")}}
+
Adds an arc to the path with the given control points and radius, connected to the previous point by a straight line.
+
{{domxref("CanvasRenderingContext2D.ellipse()", "Path2D.ellipse()")}}
+
Adds an ellipse to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
+
{{domxref("CanvasRenderingContext2D.rect()", "Path2D.rect()")}}
+
Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.
+
+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', "scripting.html#dom-path2d", "Path2D")}}{{Spec2('HTML WHATWG')}} 
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatGeckoDesktop("31")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
{{domxref("Path2D.addPath()")}}{{CompatVersionUnknown}}{{CompatGeckoDesktop("34")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatGeckoMobile("31")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
{{domxref("Path2D.addPath()")}}{{CompatVersionUnknown}}{{CompatGeckoMobile("34")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +

See also

+ + diff --git a/files/ja/web/api/path2d/path2d/index.html b/files/ja/web/api/path2d/path2d/index.html new file mode 100644 index 0000000000..2a4fbfa4da --- /dev/null +++ b/files/ja/web/api/path2d/path2d/index.html @@ -0,0 +1,109 @@ +--- +title: Path2D() +slug: Web/API/Path2D/Path2D +tags: + - API + - Canvas + - Constructor + - Drawing + - Graphics + - Path2D + - Paths + - Reference +translation_of: Web/API/Path2D/Path2D +--- +
{{APIRef("Canvas API")}}{{seeCompatTable}}
+ +

Path2D() コンストラクターは、新たにインスタンス化した Path2D オブジェクトを返します。他のパスを引数に渡すこともできます(複製がつくられます)。また、SVG パス からなるデータを文字列で渡すこともできます。

+ +

構文

+ +
new Path2D();
+new Path2D(path);
+new Path2D(d);
+
+ +

引数

+ +
+
path {{optional_inline}}
+
他のPath2D オブジェクトを渡して呼び出すと、引数の path が複製されます。
+
d {{optional_inline}}
+
SVG パス からなる文字列を渡して呼出すと、その内容のパスが新たにつくられます。
+
+ +
+
+ +

+ +

パスを複製してつくる

+ +

これは、Path2D のパスを複製して作成する簡単なコードスニペットです。

+ + + +
const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+
+let path1 = new Path2D();
+path1.rect(10, 10, 100,100);
+
+let path2 = new Path2D(path1);
+path2.moveTo(220, 60);
+path2.arc(170, 60, 50, 0, 2 * Math.PI);
+
+ctx.stroke(path2);
+
+ +

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

+ +

SVG パスを使用する

+ +

これは、SVG パスデータ を使用して Path2D のパスを作成する簡単なコードスニペットです。パスは点 (M10 10) に移ってから、水平に 80 ポイント右に移動し (h 80)、80 ポイント下がり (v 80)、80ポイント左に移動し (h -80)、開始点に戻ります (z)。

+ + + +
const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+
+let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
+ctx.fill(p);
+
+ +

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

+ +

仕様

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', '#dom-path2d', 'Path2D()')}}{{Spec2('HTML WHATWG')}}Initial definition.
+ +

ブラウザー実装状況

+ +
+ + +

{{Compat("api.Path2D")}}

+
+ +

関連情報

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