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: guide.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -934,11 +934,11 @@ Here we add an object that conforms to the [IPlayer](https://ptsjs.org/docs/?p=T
934
934
-`start` function is called when the space is ready. It includes 2 parameters: `bound` which returns the bounding box, and `space` which returns its space.
935
935
936
936
937
-
-`animate` function is called continuously when the space plays. It includes 2 parameters: `time` which gives the current running time, and `ftime` which gives the time taken to draw the previous frame.
937
+
*`animate` function is called continuously when the space plays. It includes 2 parameters: `time` which gives the current running time, and `ftime` which gives the time taken to draw the previous frame.
938
938
939
-
-`action` function is called when an user event is detected. It includes 4 parameters: `type` is a string that returns the action's name. ("up", "down", "move", "drag", "drop", "over", and "out"). `x` and `y` returns the position at which the action happened, and `event` returns the actual event object. See also: [`bindMouse`](https://ptsjs.org/docs.md#canvas-canvasspace)
939
+
*`action` function is called when an user event is detected. It includes 4 parameters: `type` is a string that returns the action's name. ("up", "down", "move", "drag", "drop", "over", and "out"). `x` and `y` returns the position at which the action happened, and `event` returns the actual event object. See also: [`bindMouse`](https://ptsjs.org/docs.md#canvas-canvasspace)
940
940
941
-
-`resize` function is called when the space is resized. It includes 2 parameter: `size` which returns the new size, and event which returns the event object. You'll also need to add `{resize: true}` in [`setup`](https://ptsjs.org/docs.md#canvas-canvasspace) to enable tracking.
941
+
*`resize` function is called when the space is resized. It includes 2 parameter: `size` which returns the new size, and event which returns the event object. You'll also need to add `{resize: true}` in [`setup`](https://ptsjs.org/docs.md#canvas-canvasspace) to enable tracking.
942
942
943
943
You may add multiple players into a space, each taking care of specific parts of a scene. Use [`add`](https://ptsjs.org/docs.md#canvas-canvasspace) and [`remove`](https://ptsjs.org/docs.md#canvas-canvasspace) to manage a space's players.
944
944
@@ -1097,7 +1097,7 @@ The following demo shows 2 paragraphs with different line-height and alignments
1097
1097
1098
1098
##### You may combine `alignText` with `paragraphBox` too.
1099
1099
1100
-
For long paragraphs, you may consider using [`fontWidthEstimate`](https://ptsjs.org/docs.md#canvas-canvasform). This will use a simple heuristic to estimate text width, which is less accurate but may be faster.
1100
+
For long paragraphs, you may consider using [`fontWidthEstimate`](https://ptsjs.org/docs.md#canvas-canvasform). This will use a simple heuristic to estimate text width, which is less accurate but may be faster.
Copy file name to clipboardExpand all lines: guide/Image-0900.html
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -96,10 +96,18 @@ <h5>Applying transforms to the pattern. Hover to rotate the pattern.</h5>
96
96
<p>It's now your turn to experiment!</p>
97
97
<h3>Tips and Tricks</h3>
98
98
<ul>
99
-
<li><p>Anticipate screens with different pixel density. You can pass a CanvasSpace's <ahref="https://ptsjs.org/docs/?p=Canvas_CanvasSpace#accessor_pixelScale"><code>pixelScale</code></a> when creating an Img instance. (See example in Cheatsheet below)</p></li>
100
-
<li><p>You can <ahref="#image-img"><code>load</code></a> an image from a base64 string or an url, or from a blob via the <ahref="#image-img"><code>fromBlob</code></a> function. To export the current image, use <ahref="#image-img"><code>toBase64</code></a> or <ahref="#image-img"><code>toBlob</code></a> functions.</p></li>
101
-
<li><p>CanvasForm's <ahref="#canvas-canvasform"><code>image</code></a> drawing function can take either an Img instance or a <ahref="https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource">CanvasImageSource</a> which includes various kinds of image objects like HTML Image or Canvas.</p></li>
102
-
<li><p>Typically, you can't load an image from another domain due to security concerns. But if the image server allows for it and you want to do it, you can set the <code>crossOrigin</code> parameter to <code>true</code> when creating an <code>Img</code> instance. <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image">More details here</a>.</p></li>
99
+
<li>
100
+
<p>Anticipate screens with different pixel density. You can pass a CanvasSpace's <ahref="https://ptsjs.org/docs/?p=Canvas_CanvasSpace#accessor_pixelScale"><code>pixelScale</code></a> when creating an Img instance. (See example in Cheatsheet below)</p>
101
+
</li>
102
+
<li>
103
+
<p>You can <ahref="#image-img"><code>load</code></a> an image from a base64 string or an url, or from a blob via the <ahref="#image-img"><code>fromBlob</code></a> function. To export the current image, use <ahref="#image-img"><code>toBase64</code></a> or <ahref="#image-img"><code>toBlob</code></a> functions.</p>
104
+
</li>
105
+
<li>
106
+
<p>CanvasForm's <ahref="#canvas-canvasform"><code>image</code></a> drawing function can take either an Img instance or a <ahref="https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource">CanvasImageSource</a> which includes various kinds of image objects like HTML Image or Canvas.</p>
107
+
</li>
108
+
<li>
109
+
<p>Typically, you can't load an image from another domain due to security concerns. But if the image server allows for it and you want to do it, you can set the <code>crossOrigin</code> parameter to <code>true</code> when creating an <code>Img</code> instance. <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image">More details here</a>.</p>
Copy file name to clipboardExpand all lines: guide/Space-0500.html
+15-9Lines changed: 15 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -55,9 +55,15 @@ <h3>Players</h3>
55
55
<li><code>start</code> function is called when the space is ready. It includes 2 parameters: <code>bound</code> which returns the bounding box, and <code>space</code> which returns its space.</li>
56
56
</ul>
57
57
<ul>
58
-
<li><p><code>animate</code> function is called continuously when the space plays. It includes 2 parameters: <code>time</code> which gives the current running time, and <code>ftime</code> which gives the time taken to draw the previous frame.</p></li>
59
-
<li><p><code>action</code> function is called when an user event is detected. It includes 4 parameters: <code>type</code> is a string that returns the action's name. ("up", "down", "move", "drag", "drop", "over", and "out"). <code>x</code> and <code>y</code> returns the position at which the action happened, and <code>event</code> returns the actual event object. See also: <ahref="#canvas-canvasspace"><code>bindMouse</code></a></p></li>
60
-
<li><p><code>resize</code> function is called when the space is resized. It includes 2 parameter: <code>size</code> which returns the new size, and event which returns the event object. You'll also need to add <code>{resize: true}</code> in <ahref="#canvas-canvasspace"><code>setup</code></a> to enable tracking.</p></li>
58
+
<li>
59
+
<p><code>animate</code> function is called continuously when the space plays. It includes 2 parameters: <code>time</code> which gives the current running time, and <code>ftime</code> which gives the time taken to draw the previous frame.</p>
60
+
</li>
61
+
<li>
62
+
<p><code>action</code> function is called when an user event is detected. It includes 4 parameters: <code>type</code> is a string that returns the action's name. ("up", "down", "move", "drag", "drop", "over", and "out"). <code>x</code> and <code>y</code> returns the position at which the action happened, and <code>event</code> returns the actual event object. See also: <ahref="#canvas-canvasspace"><code>bindMouse</code></a></p>
63
+
</li>
64
+
<li>
65
+
<p><code>resize</code> function is called when the space is resized. It includes 2 parameter: <code>size</code> which returns the new size, and event which returns the event object. You'll also need to add <code>{resize: true}</code> in <ahref="#canvas-canvasspace"><code>setup</code></a> to enable tracking.</p>
66
+
</li>
61
67
</ul>
62
68
<p>You may add multiple players into a space, each taking care of specific parts of a scene. Use <ahref="#canvas-canvasspace"><code>add</code></a> and <ahref="#canvas-canvasspace"><code>remove</code></a> to manage a space's players.</p>
63
69
<h3>Animation and interaction</h3>
@@ -91,16 +97,16 @@ <h3>Form</h3>
91
97
<h5>A demo of drawing different shapes</h5>
92
98
<p>And since both Space and Form are javascript classes, you can extend them to override its functions and add new ones.</p>
93
99
<h3>SVG Space</h3>
94
-
<p>You can switch your code from <ahref="#canvas-canvasspace"><code>CanvasSpace</code></a> to <ahref="#svg-svgspace"><code>SVGSpace</code></a> without changing your drawing code: initiate the space as <code>SVGSpace</code> instead of <code>CanvasSpace</code>, and <code>space.getForm()</code> will return an <ahref="#svg-svgform"><code>SVGForm</code></a>, which shares the complete <code>CanvasForm</code> drawing API — shapes, gradients, dashes, text and more render as svg automatically.</p>
100
+
<p>You can switch your code from <ahref="#canvas-canvasspace"><code>CanvasSpace</code></a> to <ahref="#svg-svgspace"><code>SVGSpace</code></a> without changing your drawing code: initiate the space as <code>SVGSpace</code> instead of <code>CanvasSpace</code>, and <code>space.getForm()</code> will return an <ahref="#svg-svgform"><code>SVGForm</code></a>, which shares the complete <code>CanvasForm</code> drawing API — shapes, gradients, dashes, text and more render as svg automatically.</p>
95
101
<pre><code>const space = new SVGSpace( "#elem" ).setup({ bgcolor: "#123", resize: true });
96
102
const form = space.getForm();
97
103
// ... the same drawing code as canvas
98
104
</code></pre>
99
-
<p>If you use <ahref="#play-quickstart"><code>quickStart</code></a>, it picks the space for you: mount on an <code><svg></code> element and you get an <code>SVGSpace</code>; mount on a <code><canvas></code> or <code><div></code> and you get a <code>CanvasSpace</code>. No other changes needed — a sketch written for canvas runs on svg as-is.</p>
100
-
<p>Under the hood, consecutive shapes that share styles are merged into single svg elements per frame, so the output stays fast and compact. To export the current frame as an svg file, use <ahref="#svg-svgspace"><code>SVGSpace.toSVG</code></a>— pass <code>true</code> to get one element per shape, which is easier to edit in vector graphics tools.</p>
101
-
<p>(In earlier versions of Pts, SVG rendering required a <code>form.scope(this)</code> call in each animate callback. This is no longer needed — existing code that calls it will still run, as the function is kept as a harmless no-op.)</p>
105
+
<p>If you use <ahref="#play-quickstart"><code>quickStart</code></a>, it picks the space for you: mount on an <code><svg></code> element and you get an <code>SVGSpace</code>; mount on a <code><canvas></code> or <code><div></code> and you get a <code>CanvasSpace</code>. No other changes needed — a sketch written for canvas runs on svg as-is.</p>
106
+
<p>Under the hood, consecutive shapes that share styles are merged into single svg elements per frame, so the output stays fast and compact. To export the current frame as an svg file, use <ahref="#svg-svgspace"><code>SVGSpace.toSVG</code></a>— pass <code>true</code> to get one element per shape, which is easier to edit in vector graphics tools.</p>
107
+
<p>(In earlier versions of Pts, SVG rendering required a <code>form.scope(this)</code> call in each animate callback. This is no longer needed — existing code that calls it will still run, as the function is kept as a harmless no-op.)</p>
102
108
<h3>HTML Space</h3>
103
-
<p>There is also an <ahref="#dom-htmlspace"><code>HTMLSpace</code></a> that renders forms in basic html elements. It is deprecated and will be removed in a future major version — use <ahref="#svg-svgspace"><code>SVGSpace</code></a> for DOM-based output instead. Because of the limitations of HTML, it cannot draw polygon, arc, and some other shapes.</p>
109
+
<p>There is also an <ahref="#dom-htmlspace"><code>HTMLSpace</code></a> that renders forms in basic html elements. It is deprecated and will be removed in a future major version — use <ahref="#svg-svgspace"><code>SVGSpace</code></a> for DOM-based output instead. Because of the limitations of HTML, it cannot draw polygon, arc, and some other shapes.</p>
104
110
<p>If you use Pts with React or other web rendering frameworks, it will be better to use the props and states of their virtual DOM implementations instead.</p>
105
111
<h3>Cheat sheet</h3>
106
112
<p>The quickest way to start is to use the <code>quickStart</code> function, which initiates a <ahref="#canvas-canvasspace"><code>CanvasSpace</code></a> and adds <code>space</code> and <code>form</code> instances into current scope. You can create an interactive piece in 2 lines of code:</p>
0 commit comments