-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
107 lines (96 loc) · 3.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SVG Path Playground</title>
<style>
body {
background-color: #eee;
width: 800px;
margin-left: auto;
margin-right: auto;
font-family: helvetica;
font-size: 14px;
line-height: 20px;
}
.path {
margin-top: 30px;
}
textarea {
padding: 10px;
width: 100%;
font-family: helvetica;
font-size: 14px;
line-height: 16px;
}
li {
padding-top: 5px;
padding-bottom: 5px;
}
.note {
margin-top: 5px;
font-size: .9em;
color: #666;
line-height: 1.4em;
}
code {
background-color: #ddd;
padding: 2px 6px;
border-radius: 3px;
color: #c00;
}
</style>
</head>
<body>
<h1>SVG Path Playground</h1>
<svg xmlns="http://www.w3.org/2000/svg" width="150" height="150" style="background-color: #fff;">
<path id="svg_path" d="" fill="transparent" stroke="#069" stroke-width="2"></path>
</svg>
<div class="path">
<textarea name="x" id="path" cols="30" rows="10" style="font-family: monospace;">
M 10, 10
A 10, 10, 0, 0, 1, 40, 100
</textarea>
</div>
<h2>How <path> works</h2>
<ul>
<li>Top left corner is <code>0, 0</code>.</li>
<li>x axis increses to the right, y axis increases to the down.</li>
<li>You start from <code>0, 0</code> and define your new destination coordinates with each command.</li>
<li>You can update your current position without drawing anything with the <code>M</code> command.
<li>Coordinates are absolute if the command is upper-case and relative if lower.
Case doesn't matter for the commands that are not taking parameters (i.e. <code>Z</code>)</li>
<li>Comma (,) is used to separate commands and arguments but it's optional. Arguments can be separated with space character too.
So <code>M10,10L15,15</code> and <code>M10,10, L15,15</code> are both fine.
</li>
</ul>
<h2>Commands</h2>
<ul>
<li><code>M x,y</code> Move to coordinate</li>
<li><code>L x,y</code> Line</li>
<li>
<code>A radius-x,radius-y x-axis-rotation large-arc-flag sweep-flag x,y</code> Arc
<div class="note">
<code>large-arc-flag</code>: <code>1</code>: Arc angle is more than 180, <code>0</code>: Less than 180<br>
<code>sweep-flag</code>: <code>1</code>: clockwise, <code>0</code>: anti-clockwise<br>
See this to understand how it works: <a href="https://www.w3.org/TR/SVG/images/paths/arcs02.png" target="_blank">https://www.w3.org/TR/SVG/images/paths/arcs02.png</a>
</div>
</li>
<li><code>H x</code> Horizontal line</li>
<li><code>V y</code> Vertical line</li>
<li><code>C x1,y1 x2,y2 x,y</code> Cubic bezier</li>
<li><code>S x2,y2 x,y</code> Cubic bezier shortcut</li>
<li><code>Q x1,y1 x,y</code> Quadratic bezier curve</li>
<li><code>T x,y</code> Quadratic bezier curve shortcut</li>
<li><code>Z</code> Close path</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(function () {
$('#path').keyup(function() {
$('#svg_path').attr('d', $(this).val());
}).trigger('keyup').focus();
});
</script>
</body>
</html>