You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: files/en-us/web/api/path2d/path2d/index.md
+8-15Lines changed: 8 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,7 @@ browser-compat: api.Path2D.Path2D
8
8
9
9
{{APIRef("Canvas API")}}{{AvailableInWorkers}}
10
10
11
-
The **`Path2D()`** constructor returns a newly instantiated
12
-
`Path2D` object, optionally with another path as an argument (creates a
13
-
copy), or optionally with a string consisting of [SVG path](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths) data.
11
+
The **`Path2D()`** constructor returns a newly instantiated `Path2D` object, optionally with another path as an argument (creates a copy), or optionally with a string consisting of [SVG path](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths) data.
14
12
15
13
## Syntax
16
14
@@ -23,17 +21,15 @@ new Path2D(d)
23
21
### Parameters
24
22
25
23
-`path` {{optional_inline}}
26
-
- : When invoked with another `Path2D` object, a copy of the
27
-
`path` argument is created.
24
+
- : When invoked with another `Path2D` object, a copy of the `path` argument is created.
28
25
-`d` {{optional_inline}}
29
-
- : When invoked with a string consisting of [SVG path](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths) data, a new path is created
30
-
from that description.
26
+
- : When invoked with a string consisting of [SVG path](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths) data, a new path is created from that description.
31
27
32
28
## Examples
33
29
34
30
### Creating and copying paths
35
31
36
-
This example creates and copies a `Path2D` path.
32
+
This example creates and copies a `Path2D` path. First, `path1` is a rectangular path. Then, we copy `path1` into `path2` and add a circle to it. Finally, we stroke `path2`, which contains both the rectangle and the circle. Note that `path1` remains unchanged, although we never draw it to the canvas. Its only purpose is to show how you can build up a complex path by building on existing paths.
37
33
38
34
```html hidden
39
35
<canvasid="canvas"></canvas>
@@ -43,10 +39,10 @@ This example creates and copies a `Path2D` path.
43
39
constcanvas=document.getElementById("canvas");
44
40
constctx=canvas.getContext("2d");
45
41
46
-
let path1 =newPath2D();
42
+
constpath1=newPath2D();
47
43
path1.rect(10, 10, 100, 100);
48
44
49
-
let path2 =newPath2D(path1);
45
+
constpath2=newPath2D(path1);
50
46
path2.moveTo(220, 60);
51
47
path2.arc(170, 60, 50, 0, 2*Math.PI);
52
48
@@ -57,10 +53,7 @@ ctx.stroke(path2);
57
53
58
54
### Using SVG paths
59
55
60
-
This example creates a `Path2D` path using [SVG path data](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths). The path will move to
61
-
point (`M10 10`) and then move horizontally 80 points to the right
62
-
(`h 80`), then 80 points down (`v 80`), then 80 points to the left
63
-
(`h -80`), and then back to the start (`Z`).
56
+
This example creates a `Path2D` path using [SVG path data](/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths). The path will move to point (`M10 10`) and then move horizontally 80 points to the right (`h 80`), then 80 points down (`v 80`), then 80 points to the left (`h -80`), and then back to the start (`Z`).
64
57
65
58
```html hidden
66
59
<canvasid="canvas"></canvas>
@@ -70,7 +63,7 @@ point (`M10 10`) and then move horizontally 80 points to the right
0 commit comments