|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Graphics: Path Drawing Tool</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Graphics: Path Drawing Tool</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><div class="intro" style="min-height: 184px;"> |
|
|
29 |
<p> |
|
|
30 |
<img src="../assets/graphics/img/path-tool-capture.png" alt="Screen capture of Graphics path tool" style="border: 1px solid #bfbfbf; float:right; height:149px; margin: 0 0 8px 8px; width:395px;"/> |
|
|
31 |
This simple tool helps you by generating code while you interactively |
|
|
32 |
draw graphic paths. This was used to draw the <a href="graphics-violin.html">violin example</a>. |
|
|
33 |
</p> |
|
|
34 |
</div> |
|
|
35 |
|
|
|
36 |
<div class="example newwindow"> |
|
|
37 |
<a href="graphics-path-tool-example.html" target="_blank" class="button"> |
|
|
38 |
Run Tool in New Window |
|
|
39 |
</a> |
|
|
40 |
</div> |
|
|
41 |
|
|
|
42 |
<h2>The Path Tool</h2> |
|
|
43 |
|
|
|
44 |
<p>As you drag the pencil icon, corresponding graphics code is auto-generated. |
|
|
45 |
This code can be copied and pasted into a graphics instance to reproduce |
|
|
46 |
the paths you created with the pencil. |
|
|
47 |
</p> |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
<h2>Initial State</h2> |
|
|
51 |
<p>When the tool window is loaded, its generated code is placed |
|
|
52 |
in the text area control. The generated code assumes you will have a separate |
|
|
53 |
page to paste it into. This separate page must contain the following code: |
|
|
54 |
A graphics container such as this,</p> |
|
|
55 |
<pre class="code prettyprint"><div id="mygraphiccontainer"></div></pre> |
|
|
56 |
|
|
|
57 |
<p>CSS such as this,</p> |
|
|
58 |
<pre class="code prettyprint">#mygraphiccontainer { |
|
|
59 |
position: relative; |
|
|
60 |
width: 700px; |
|
|
61 |
height:400px; |
|
|
62 |
}</pre> |
|
|
63 |
|
|
|
64 |
and a YUI instance containing a <code>Graphics</code> object such as this. |
|
|
65 |
<pre class="code prettyprint">YUI().use('graphics', function (Y) { |
|
|
66 |
|
|
|
67 |
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}); |
|
|
68 |
// generated code from the path tool goes here |
|
|
69 |
|
|
|
70 |
});</pre> |
|
|
71 |
|
|
|
72 |
<p>The tool generates paste-able code for an <code>addShape</code> method that will |
|
|
73 |
create and render a path. It generates some fill and stroke placeholder code. |
|
|
74 |
You can change this to change the attributes of the fill and stroke |
|
|
75 |
after it's pasted into your code.</p> |
|
|
76 |
<p><Strong>Note:</strong> |
|
|
77 |
As you draw paths with the pencil, they won't have these attributes; you'll |
|
|
78 |
only see thin, red lines for precision. The placeholder attributes below will |
|
|
79 |
only show after you paste the code in your page.</p> |
|
|
80 |
<pre class="code prettyprint">{ |
|
|
81 |
type: "path", |
|
|
82 |
stroke: { |
|
|
83 |
weight: 2, |
|
|
84 |
color: "#00dd00" |
|
|
85 |
}, |
|
|
86 |
fill: { |
|
|
87 |
type: "linear", |
|
|
88 |
stops: [ |
|
|
89 |
{color: "#cc0000", opacity: 1, offset: 0}, |
|
|
90 |
{color: "#00cc00", opacity: 0.3, offset: 0.8} // Opacity of stops not available in IE |
|
|
91 |
] |
|
|
92 |
} |
|
|
93 |
}</pre> |
|
|
94 |
|
|
|
95 |
|
|
|
96 |
<h2>LineTo (Drag Pencil)</h2> |
|
|
97 |
<p>Drag the pencil icon. The <code>drag:end</code> event sets the <code>lineTo</code> XY value.</p> |
|
|
98 |
|
|
|
99 |
<h2>MoveTo (Shift + Drag)</h2> |
|
|
100 |
<p>Drag the pencil icon with the shift key down to move without drawing a line.</p> |
|
|
101 |
|
|
|
102 |
<h2>CurveTo (Alt + Drag)</h2> |
|
|
103 |
<p>Drag the pencil icon with the alt key down. This draws a curve and displays |
|
|
104 |
two draggable control points. The curve adjusts while you drag the control points. |
|
|
105 |
Clicking the pencil icon, or starting another line, finalizes the <code>curveTo</code>.</p> |
|
|
106 |
|
|
|
107 |
<h2>New Path Object</h2> |
|
|
108 |
<p>Crate a new path object with a new name by changing the name in the |
|
|
109 |
'Graphic Object Name' text input, then clicking the 'New' button.</p> |
|
|
110 |
|
|
|
111 |
<h2>Trace an Image</h2> |
|
|
112 |
<p>You can modify the CSS of #mygraphiccontainer to include an image background. |
|
|
113 |
This will allow you to trace the contours of an image.</p> |
|
|
114 |
|
|
|
115 |
<pre class="code prettyprint">#mygraphiccontainer { |
|
|
116 |
background: url(assets/images/my-dog.jpg); |
|
|
117 |
}</pre> |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
<img src="../assets/graphics/img/my-dog.jpg" alt="Tracing a picture of my dog |
|
|
121 |
with a Graphics path" width="652" height="268"/> |
|
|
122 |
|
|
|
123 |
zooming the browser can be helpful in accuracy. |
|
|
124 |
|
|
|
125 |
</div> |
|
|
126 |
</div> |
|
|
127 |
</div> |
|
|
128 |
|
|
|
129 |
<div class="yui3-u-1-4"> |
|
|
130 |
<div class="sidebar"> |
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
<div class="sidebox"> |
|
|
135 |
<div class="hd"> |
|
|
136 |
<h2 class="no-toc">Examples</h2> |
|
|
137 |
</div> |
|
|
138 |
|
|
|
139 |
<div class="bd"> |
|
|
140 |
<ul class="examples"> |
|
|
141 |
|
|
|
142 |
|
|
|
143 |
<li data-description="Shows how to create a Graphic instance and add shapes."> |
|
|
144 |
<a href="graphics-simple.html">Basic Graphics Implementation</a> |
|
|
145 |
</li> |
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
<li data-description="Shows how to draw lines and polygons."> |
|
|
150 |
<a href="graphics-path.html">Basic Path</a> |
|
|
151 |
</li> |
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
<li data-description="Shows how to create linear and radial gradient fills."> |
|
|
156 |
<a href="graphics-gradients.html">Create Gradient Fills</a> |
|
|
157 |
</li> |
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
<li data-description="Shows how to add drag to a shape."> |
|
|
162 |
<a href="graphics-drag.html">Basic drag with graphic object</a> |
|
|
163 |
</li> |
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
<li data-description="Shows how to apply transforms to shape."> |
|
|
168 |
<a href="graphics-transforms.html">Using Transforms</a> |
|
|
169 |
</li> |
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
<li data-description="Shows how to use a custom shape with the Graphics module."> |
|
|
174 |
<a href="graphics-customshape.html">Custom Shape</a> |
|
|
175 |
</li> |
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
<li data-description="Shows to use the graphics api to draw a realistic glass."> |
|
|
180 |
<a href="graphics-muddyglass.html">Transparent Glass with Shadow</a> |
|
|
181 |
</li> |
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
<li data-description="Shows to use the graphics api to draw a violin."> |
|
|
186 |
<a href="graphics-violin.html">Complex Drawing: Violin</a> |
|
|
187 |
</li> |
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
</ul> |
|
|
193 |
</div> |
|
|
194 |
</div> |
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
<div class="sidebox"> |
|
|
199 |
<div class="hd"> |
|
|
200 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
201 |
</div> |
|
|
202 |
|
|
|
203 |
<div class="bd"> |
|
|
204 |
<ul class="examples"> |
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
<li data-description="This example demonstrates animating an element along a curved path using bezier control points."> |
|
|
224 |
<a href="../anim/curve.html">Animating Along a Curved Path</a> |
|
|
225 |
</li> |
|
|
226 |
|
|
|
227 |
|
|
|
228 |
</ul> |
|
|
229 |
</div> |
|
|
230 |
</div> |
|
|
231 |
|
|
|
232 |
</div> |
|
|
233 |
</div> |
|
|
234 |
</div> |
|
|
235 |
</div> |
|
|
236 |
|
|
|
237 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
238 |
<script>prettyPrint();</script> |
|
|
239 |
|
|
|
240 |
<script> |
|
|
241 |
YUI.Env.Tests = { |
|
|
242 |
examples: [], |
|
|
243 |
project: '../assets', |
|
|
244 |
assets: '../assets/graphics', |
|
|
245 |
name: 'graphics', |
|
|
246 |
title: 'Graphics: Path Drawing Tool', |
|
|
247 |
newWindow: '', |
|
|
248 |
auto: false |
|
|
249 |
}; |
|
|
250 |
YUI.Env.Tests.examples.push('graphics-simple'); |
|
|
251 |
YUI.Env.Tests.examples.push('graphics-path'); |
|
|
252 |
YUI.Env.Tests.examples.push('graphics-gradients'); |
|
|
253 |
YUI.Env.Tests.examples.push('graphics-drag'); |
|
|
254 |
YUI.Env.Tests.examples.push('graphics-transforms'); |
|
|
255 |
YUI.Env.Tests.examples.push('graphics-customshape'); |
|
|
256 |
YUI.Env.Tests.examples.push('graphics-muddyglass'); |
|
|
257 |
YUI.Env.Tests.examples.push('graphics-violin'); |
|
|
258 |
YUI.Env.Tests.examples.push('curve'); |
|
|
259 |
|
|
|
260 |
</script> |
|
|
261 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
</body> |
|
|
266 |
</html> |