UNPKG

scrawl-canvas

Version:
1,070 lines (702 loc) 50.7 kB
<!DOCTYPE html> <html> <head> <title>Oval factory</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page_wrapper"> <div id="jump_page"> <a class="source" href="../core/animationloop.html"> ./source/core/animationloop.js </a> <a class="source" href="../core/document.html"> ./source/core/document.js </a> <a class="source" href="../core/events.html"> ./source/core/events.js </a> <a class="source" href="../core/init.html"> ./source/core/init.js </a> <a class="source" href="../core/library.html"> ./source/core/library.js </a> <a class="source" href="../core/random-seed.html"> ./source/core/random-seed.js </a> <a class="source" href="../core/snippets.html"> ./source/core/snippets.js </a> <a class="source" href="../core/userInteraction.html"> ./source/core/userInteraction.js </a> <a class="source" href="../core/utilities.html"> ./source/core/utilities.js </a> <a class="source" href="action.html"> ./source/factory/action.js </a> <a class="source" href="anchor.html"> ./source/factory/anchor.js </a> <a class="source" href="animation.html"> ./source/factory/animation.js </a> <a class="source" href="bezier.html"> ./source/factory/bezier.js </a> <a class="source" href="block.html"> ./source/factory/block.js </a> <a class="source" href="canvas.html"> ./source/factory/canvas.js </a> <a class="source" href="cell.html"> ./source/factory/cell.js </a> <a class="source" href="cog.html"> ./source/factory/cog.js </a> <a class="source" href="color.html"> ./source/factory/color.js </a> <a class="source" href="conicGradient.html"> ./source/factory/conicGradient.js </a> <a class="source" href="coordinate.html"> ./source/factory/coordinate.js </a> <a class="source" href="crescent.html"> ./source/factory/crescent.js </a> <a class="source" href="element.html"> ./source/factory/element.js </a> <a class="source" href="emitter.html"> ./source/factory/emitter.js </a> <a class="source" href="filter.html"> ./source/factory/filter.js </a> <a class="source" href="filterEngine-bluenoiseData.html"> ./source/factory/filterEngine-bluenoiseData.js </a> <a class="source" href="filterEngine.html"> ./source/factory/filterEngine.js </a> <a class="source" href="fontAttributes.html"> ./source/factory/fontAttributes.js </a> <a class="source" href="gradient.html"> ./source/factory/gradient.js </a> <a class="source" href="grid.html"> ./source/factory/grid.js </a> <a class="source" href="group.html"> ./source/factory/group.js </a> <a class="source" href="imageAsset.html"> ./source/factory/imageAsset.js </a> <a class="source" href="line.html"> ./source/factory/line.js </a> <a class="source" href="lineSpiral.html"> ./source/factory/lineSpiral.js </a> <a class="source" href="loom.html"> ./source/factory/loom.js </a> <a class="source" href="mesh.html"> ./source/factory/mesh.js </a> <a class="source" href="net.html"> ./source/factory/net.js </a> <a class="source" href="noiseAsset.html"> ./source/factory/noiseAsset.js </a> <a class="source" href="oval.html"> ./source/factory/oval.js </a> <a class="source" href="palette.html"> ./source/factory/palette.js </a> <a class="source" href="particle.html"> ./source/factory/particle.js </a> <a class="source" href="particleForce.html"> ./source/factory/particleForce.js </a> <a class="source" href="particleHistory.html"> ./source/factory/particleHistory.js </a> <a class="source" href="particleSpring.html"> ./source/factory/particleSpring.js </a> <a class="source" href="particleWorld.html"> ./source/factory/particleWorld.js </a> <a class="source" href="pattern.html"> ./source/factory/pattern.js </a> <a class="source" href="phrase.html"> ./source/factory/phrase.js </a> <a class="source" href="picture.html"> ./source/factory/picture.js </a> <a class="source" href="polygon.html"> ./source/factory/polygon.js </a> <a class="source" href="polyline.html"> ./source/factory/polyline.js </a> <a class="source" href="quadratic.html"> ./source/factory/quadratic.js </a> <a class="source" href="quaternion.html"> ./source/factory/quaternion.js </a> <a class="source" href="radialGradient.html"> ./source/factory/radialGradient.js </a> <a class="source" href="rawAsset.html"> ./source/factory/rawAsset.js </a> <a class="source" href="rdAsset.html"> ./source/factory/rdAsset.js </a> <a class="source" href="rectangle.html"> ./source/factory/rectangle.js </a> <a class="source" href="renderAnimation.html"> ./source/factory/renderAnimation.js </a> <a class="source" href="shape.html"> ./source/factory/shape.js </a> <a class="source" href="spiral.html"> ./source/factory/spiral.js </a> <a class="source" href="spriteAsset.html"> ./source/factory/spriteAsset.js </a> <a class="source" href="stack.html"> ./source/factory/stack.js </a> <a class="source" href="star.html"> ./source/factory/star.js </a> <a class="source" href="state.html"> ./source/factory/state.js </a> <a class="source" href="tetragon.html"> ./source/factory/tetragon.js </a> <a class="source" href="ticker.html"> ./source/factory/ticker.js </a> <a class="source" href="tracer.html"> ./source/factory/tracer.js </a> <a class="source" href="tween.html"> ./source/factory/tween.js </a> <a class="source" href="unstackedElement.html"> ./source/factory/unstackedElement.js </a> <a class="source" href="vector.html"> ./source/factory/vector.js </a> <a class="source" href="videoAsset.html"> ./source/factory/videoAsset.js </a> <a class="source" href="wheel.html"> ./source/factory/wheel.js </a> <a class="source" href="../mixin/anchor.html"> ./source/mixin/anchor.js </a> <a class="source" href="../mixin/asset.html"> ./source/mixin/asset.js </a> <a class="source" href="../mixin/assetAdvancedFunctionality.html"> ./source/mixin/assetAdvancedFunctionality.js </a> <a class="source" href="../mixin/assetConsumer.html"> ./source/mixin/assetConsumer.js </a> <a class="source" href="../mixin/base.html"> ./source/mixin/base.js </a> <a class="source" href="../mixin/cascade.html"> ./source/mixin/cascade.js </a> <a class="source" href="../mixin/delta.html"> ./source/mixin/delta.js </a> <a class="source" href="../mixin/displayShape.html"> ./source/mixin/displayShape.js </a> <a class="source" href="../mixin/dom.html"> ./source/mixin/dom.js </a> <a class="source" href="../mixin/entity.html"> ./source/mixin/entity.js </a> <a class="source" href="../mixin/filter.html"> ./source/mixin/filter.js </a> <a class="source" href="../mixin/mimic.html"> ./source/mixin/mimic.js </a> <a class="source" href="../mixin/path.html"> ./source/mixin/path.js </a> <a class="source" href="../mixin/pattern.html"> ./source/mixin/pattern.js </a> <a class="source" href="../mixin/pivot.html"> ./source/mixin/pivot.js </a> <a class="source" href="../mixin/position.html"> ./source/mixin/position.js </a> <a class="source" href="../mixin/shapeBasic.html"> ./source/mixin/shapeBasic.js </a> <a class="source" href="../mixin/shapeCurve.html"> ./source/mixin/shapeCurve.js </a> <a class="source" href="../mixin/shapePathCalculation.html"> ./source/mixin/shapePathCalculation.js </a> <a class="source" href="../mixin/styles.html"> ./source/mixin/styles.js </a> <a class="source" href="../mixin/tween.html"> ./source/mixin/tween.js </a> </div> </div> </li> </ul> <ul class="sections"> <li id="section-1"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-1">&#x00a7;</a> </div> <h1 id="oval-factory">Oval factory</h1> <p>A factory for generating oval shape-based entitys</p> <p>Path-defined entitys represent a diverse range of shapes rendered onto a DOM &lt;canvas&gt; element using the Canvas API’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/Path2D">Path2D interface</a>. They use the <a href="../mixin/shapeBasic.html">shapeBasic</a> and <a href="../mixin/shapePathCalculation.html">shapePathCalculation</a> (some also use <a href="../mixin/shapeCurve.html">shapeCurve</a>) mixins to define much of their functionality.</p> <p>All path-defined entitys can be positioned, cloned, filtered etc:</p> <ul> <li>Positioning functionality for the entity is supplied by the <strong>position</strong> mixin, while rendering functionality comes from the <strong>entity</strong> mixin. </li> <li>Dimensions, however, have little meaning for path-defined entitys - their width and height are determined by their SVG path data Strings; use <code>scale</code> instead.</li> <li>Path-defined entitys can use CSS color Strings for their fillStyle and strokeStyle values, alongside <strong>Gradient</strong>, <strong>RadialGradient</strong>, <strong>Color</strong> and <strong>Pattern</strong> objects. </li> <li>They will also accept <strong>Filter</strong> objects.</li> <li>They can use <strong>Anchor</strong> objects for user navigation. </li> <li>They can be rendered to the canvas by including them in a <strong>Cell</strong> object’s <strong>Group</strong>. </li> <li>They can be <strong>animated</strong> directly, or using delta animation, or act as the target for <strong>Tween</strong> animations.</li> <li>Path-defined entitys can be cloned, and killed.</li> </ul> </div> </li> <li id="section-2"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-2">&#x00a7;</a> </div> <h4 id="using-path-defined-entitys-as-scrawl-canvas-paths">Using path-defined entitys as Scrawl-canvas paths</h4> <p>A path is a track - straight, or curved, or as complex as required - placed across a container which artefacts can use as a source of their positioning data. We can animate an artifact to move along the path:</p> <ul> <li>To enable a path-defined entity to be used as a path by other artefacts, set its <code>useAsPath</code> flag to <code>true</code>.</li> <li>The artefact can then set its <code>path</code> attribute to the path-defined entity’s name-String (or the entity itself), and set its <code>lockTo</code> Array values to <code>&quot;path&quot;</code>.</li> <li>We position the artefact by setting its <code>pathPosition</code> attribute to a float Number value between <code>0.0 - 1.0</code>, with <code>0</code> being the start of the path, and <code>1</code> being its end.</li> <li>Path-defined entitys can use other path-defined entitys as a path.</li> <li>Phrase entitys can use a path to position their text block; they can also use a path to position each letter individually along the path.</li> <li>Artefacts (and letters) can be rotated so that they match the rotation at that point along the path - <em><strong>tangential rotation</strong></em> by setting their <code>addPathRotation</code> flag to <code>true</code>.</li> <li>Animate an artefact along the path by either using the artefact’s <code>delta</code> object, or triggering a Tween to perform the movement.</li> </ul> </div> </li> <li id="section-3"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-3">&#x00a7;</a> </div> <h4 id="demos">Demos:</h4> <ul> <li><a href="../../demo/canvas-011.html">Canvas-011</a> - Shape entity (make, clone, method); drag and drop shape entitys</li> <li><a href="../../demo/canvas-012.html">Canvas-012</a> - Shape entity position; shape entity as a path for other artefacts to follow</li> <li><a href="../../demo/canvas-013.html">Canvas-013</a> - Path-defined entitys: oval, rectangle, line, quadratic, bezier, tetragon, polygon, star, spiral</li> <li><a href="../../demo/canvas-014.html">Canvas-014</a> - Line, quadratic and bezier entitys - control lock alternatives</li> <li><a href="../../demo/canvas-018.html">Canvas-018</a> - Phrase entity - text along a path</li> <li><a href="../../demo/canvas-024.html">Canvas-024</a> - Loom entity functionality</li> <li><a href="../../demo/canvas-030.html">Canvas-030</a> - Polyline entity functionality</li> <li><a href="../../demo/canvas-038.html">Canvas-038</a> - Responsive Shape-based entitys</li> <li><a href="../../demo/dom-015.html">DOM-015</a> - Use stacked DOM artefact corners as pivot points</li> <li><a href="../../demo/packets-002.html">Packets-002</a> - Scrawl-canvas packets - save and load a range of different entitys</li> </ul> </div> </li> <li id="section-4"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-4">&#x00a7;</a> </div> <h4 id="imports">Imports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/base.js&#x27;</span>; <span class="hljs-keyword">import</span> shapeMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/shapeBasic.js&#x27;</span>;</pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-5">&#x00a7;</a> </div> <h4 id="oval-constructor">Oval constructor</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Oval</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">shapeInit</span>(items); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-6">&#x00a7;</a> </div> <h4 id="oval-prototype">Oval prototype</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Oval</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>); P.<span class="hljs-property">type</span> = <span class="hljs-string">&#x27;Oval&#x27;</span>; P.<span class="hljs-property">lib</span> = <span class="hljs-string">&#x27;entity&#x27;</span>; P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">true</span>; P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">false</span>;</pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-7">&#x00a7;</a> </div> <h4 id="mixins">Mixins</h4> <ul> <li><a href="../mixin/base.html">base</a></li> <li><a href="../mixin/shapeBasic.html">shapeBasic</a></li> </ul> </div> <div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P); P = <span class="hljs-title function_">shapeMix</span>(P);</pre></div></div> </li> <li id="section-8"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-8">&#x00a7;</a> </div> <h4 id="oval-attributes">Oval attributes</h4> <ul> <li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li> <li>Attributes defined in the <a href="../mixin/position.html">position mixin</a>: <strong>group, visibility, order, calculateOrder, stampOrder, start, <em>startX</em>, <em>startY</em>, handle, <em>handleX</em>, <em>handleY</em>, offset, <em>offsetX</em>, <em>offsetY</em>, dimensions, <em>width</em>, <em>height</em>, pivoted, mimicked, lockTo, <em>lockXTo</em>, <em>lockYTo</em>, scale, roll, noUserInteraction, noPositionDependencies, noCanvasEngineUpdates, noFilters, noPathUpdates, purge, bringToFrontOnDrag</strong>.</li> <li>Attributes defined in the <a href="../mixin/delta.html">delta mixin</a>: <strong>delta, noDeltaUpdates</strong>.</li> <li>Attributes defined in the <a href="../mixin/pivot.html">pivot mixin</a>: <strong>pivot, pivotCorner, addPivotHandle, addPivotOffset, addPivotRotation</strong>.</li> <li>Attributes defined in the <a href="../mixin/mimic.html">mimic mixin</a>: <strong>mimic, useMimicDimensions, useMimicScale, useMimicStart, useMimicHandle, useMimicOffset, useMimicRotation, useMimicFlip, addOwnDimensionsToMimic, addOwnScaleToMimic, addOwnStartToMimic, addOwnHandleToMimic, addOwnOffsetToMimic, addOwnRotationToMimic</strong>.</li> <li>Attributes defined in the <a href="../mixin/path.html">path mixin</a>: <strong>path, pathPosition, addPathHandle, addPathOffset, addPathRotation, constantPathSpeed</strong>.</li> <li>Attributes defined in the <a href="../mixin/entity.html">entity mixin</a>: <strong>method, pathObject, winding, flipReverse, flipUpend, scaleOutline, lockFillStyleToEntity, lockStrokeStyleToEntity, onEnter, onLeave, onDown, onUp, <em>fillStyle, strokeStyle, globalAlpha, globalCompositeOperation, lineWidth, lineCap, lineJoin, lineDash, lineDashOffset, miterLimit, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, filter</em></strong>.</li> <li>Attributes defined in the <a href="../mixin/anchor.html">anchor mixin</a>: <strong>anchor</strong>.</li> <li>Attributes defined in the <a href="../mixin/filter.html">filter mixin</a>: <strong>filters, isStencil</strong>.</li> <li>Attributes defined in the <a href="../mixin/shapeBasic.html">shapeBasic mixin</a>: <strong>species, useAsPath, precision, pathDefinition, showBoundingBox, boundingBoxColor, minimumBoundingBoxDimensions, constantPathSpeed</strong>.</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = { <span class="hljs-attr">radiusX</span>: <span class="hljs-number">5</span>, <span class="hljs-attr">radiusY</span>: <span class="hljs-number">5</span>, <span class="hljs-attr">intersectX</span>: <span class="hljs-number">0.5</span>, <span class="hljs-attr">intersectY</span>: <span class="hljs-number">0.5</span>, <span class="hljs-attr">offshootA</span>: <span class="hljs-number">0.55</span>, <span class="hljs-attr">offshootB</span>: <span class="hljs-number">0</span>, }; P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-9">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> <p>No additional packet functionality required</p> </div> </li> <li id="section-10"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-10">&#x00a7;</a> </div> <h4 id="clone-management">Clone management</h4> <p>No additional clone functionality required</p> </div> </li> <li id="section-11"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-11">&#x00a7;</a> </div> <h4 id="kill-management">Kill management</h4> <p>No additional kill functionality required</p> </div> </li> <li id="section-12"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-12">&#x00a7;</a> </div> <h4 id="get-set-deltaset">Get, Set, deltaSet</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> S = P.<span class="hljs-property">setters</span>, D = P.<span class="hljs-property">deltaSetters</span>; S.<span class="hljs-property">radius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusX&#x27;</span>, <span class="hljs-string">&#x27;radiusY&#x27;</span>]); }; S.<span class="hljs-property">radiusX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusX&#x27;</span>]); }; S.<span class="hljs-property">radiusY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusY&#x27;</span>]); }; D.<span class="hljs-property">radius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deltaRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusX&#x27;</span>, <span class="hljs-string">&#x27;radiusY&#x27;</span>]); }; D.<span class="hljs-property">radiusX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deltaRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusX&#x27;</span>]); }; D.<span class="hljs-property">radiusY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deltaRectHelper</span>(item, [<span class="hljs-string">&#x27;radiusY&#x27;</span>]); }; S.<span class="hljs-property">offshootA</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootA</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); }; S.<span class="hljs-property">offshootB</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootB</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); }; D.<span class="hljs-property">offshootA</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootA</span> += item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); } }; D.<span class="hljs-property">offshootB</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootB</span> += item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); } }; S.<span class="hljs-property">intersectA</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectA</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); }; S.<span class="hljs-property">intersectB</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectB</span> = item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); }; D.<span class="hljs-property">intersectA</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectA</span> += item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); } }; D.<span class="hljs-property">intersectB</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectB</span> += item; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); } };</pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <h4 id="prototype-functions">Prototype functions</h4> </div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <p><code>setRectHelper</code> - internal setter helper function</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">setRectHelper</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item, corners</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); corners.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">corner</span> =&gt;</span> { <span class="hljs-variable language_">this</span>[corner] = item; }, <span class="hljs-variable language_">this</span>); };</pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</a> </div> <p><code>deltaRectHelper</code> - internal setter helper function</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">deltaRectHelper</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item, corners</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">updateDirty</span>(); corners.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">corner</span> =&gt;</span> { <span class="hljs-variable language_">this</span>[corner] = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>[corner], item); }, <span class="hljs-variable language_">this</span>); };</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <p><code>cleanSpecies</code> - internal helper function - called by <code>prepareStamp</code></p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">cleanSpecies</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtySpecies</span> = <span class="hljs-literal">false</span>; <span class="hljs-keyword">let</span> p = <span class="hljs-string">&#x27;M0,0&#x27;</span>; p = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">makeOvalPath</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathDefinition</span> = p; };</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <p><code>makeOvalPath</code> - internal helper function - called by <code>cleanSpecies</code></p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">makeOvalPath</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">let</span> A = <span class="hljs-built_in">parseFloat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootA</span>.<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">6</span>)), B = <span class="hljs-built_in">parseFloat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">offshootB</span>.<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">6</span>)), radiusX = <span class="hljs-variable language_">this</span>.<span class="hljs-property">radiusX</span>, radiusY = <span class="hljs-variable language_">this</span>.<span class="hljs-property">radiusY</span>, width, height; <span class="hljs-keyword">if</span> (radiusX.<span class="hljs-property">substring</span> || radiusY.<span class="hljs-property">substring</span>) {</pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <p>let here = this.getHere();</p> </div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <p>let rx = (radiusX.substring) ? (parseFloat(radiusX) / 100) * here.w : radiusX, ry = (radiusY.substring) ? (parseFloat(radiusY) / 100) * here.h : radiusY;</p> </div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <p>width = rx * 2; height = ry * 2;</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> host = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">getHost</span>(); <span class="hljs-keyword">if</span> (host) { <span class="hljs-keyword">let</span> [hW, hH] = host.<span class="hljs-property">currentDimensions</span>; <span class="hljs-keyword">let</span> rx = (radiusX.<span class="hljs-property">substring</span>) ? (<span class="hljs-built_in">parseFloat</span>(radiusX) / <span class="hljs-number">100</span>) * hW : radiusX, ry = (radiusY.<span class="hljs-property">substring</span>) ? (<span class="hljs-built_in">parseFloat</span>(radiusY) / <span class="hljs-number">100</span>) * hH : radiusY; width = rx * <span class="hljs-number">2</span>; height = ry * <span class="hljs-number">2</span>; } } <span class="hljs-keyword">else</span> { width = radiusX * <span class="hljs-number">2</span>; height = radiusY * <span class="hljs-number">2</span>; } <span class="hljs-keyword">let</span> port = <span class="hljs-built_in">parseFloat</span>((width * <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectX</span>).<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">2</span>)), starboard = <span class="hljs-built_in">parseFloat</span>((width - port).<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">2</span>)), fore = <span class="hljs-built_in">parseFloat</span>((height * <span class="hljs-variable language_">this</span>.<span class="hljs-property">intersectY</span>).<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">2</span>)), aft = <span class="hljs-built_in">parseFloat</span>((height - fore).<span class="hljs-title function_">toFixed</span>(<span class="hljs-number">2</span>)); <span class="hljs-keyword">let</span> myData = <span class="hljs-string">`m0,0`</span>; myData += <span class="hljs-string">`c<span class="hljs-subst">${starboard * A}</span>,<span class="hljs-subst">${fore * B}</span> <span class="hljs-subst">${starboard - (starboard * B)}</span>,<span class="hljs-subst">${fore - (fore * A)}</span>, <span class="hljs-subst">${starboard}</span>,<span class="hljs-subst">${fore}</span> `</span>; myData += <span class="hljs-string">`<span class="hljs-subst">${-starboard * B}</span>,<span class="hljs-subst">${aft * A}</span> <span class="hljs-subst">${-starboard + (starboard * A)}</span>,<span class="hljs-subst">${aft - (aft * B)}</span> <span class="hljs-subst">${-starboard}</span>,<span class="hljs-subst">${aft}</span> `</span>; myData += <span class="hljs-string">`<span class="hljs-subst">${-port * A}</span>,<span class="hljs-subst">${-aft * B}</span> <span class="hljs-subst">${-port + (port * B)}</span>,<span class="hljs-subst">${-aft + (aft * A)}</span> <span class="hljs-subst">${-port}</span>,<span class="hljs-subst">${-aft}</span> `</span>; myData += <span class="hljs-string">`<span class="hljs-subst">${port * B}</span>,<span class="hljs-subst">${-fore * A}</span> <span class="hljs-subst">${port - (port * A)}</span>,<span class="hljs-subst">${-fore + (fore * B)}</span> <span class="hljs-subst">${port}</span>,<span class="hljs-subst">${-fore}</span>z`</span>; <span class="hljs-keyword">return</span> myData; }; P.<span class="hljs-property">calculateLocalPathAdditionalActions</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">let</span> [x, y, w, h] = <span class="hljs-variable language_">this</span>.<span class="hljs-property">localBox</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathDefinition</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathDefinition</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-string">&#x27;m0,0&#x27;</span>, <span class="hljs-string">`m<span class="hljs-subst">${-x}</span>,<span class="hljs-subst">${-y}</span>`</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathCalculatedOnce</span> = <span class="hljs-literal">false</span>;</pre></div></div> </li> <li id="section-21"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-21">&#x00a7;</a> </div> <p>ALWAYS, when invoking <code>calculateLocalPath</code> from <code>calculateLocalPathAdditionalActions</code>, include the second argument, set to <code>true</code>! Failure to do this leads to an infinite loop which will make your machine weep.</p> <ul> <li>We need to recalculate the local path to take into account the offset required to put the Oval entity’s start coordinates at the top-left of the local box, and to recalculate the data used by other artefacts to place themselves on, or move along, its path.</li> </ul> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">calculateLocalPath</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">pathDefinition</span>, <span class="hljs-literal">true</span>); };</pre></div></div> </li> <li id="section-22"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-22">&#x00a7;</a> </div> <h4 id="factories">Factories</h4> </div> </li> <li id="section-23"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-23">&#x00a7;</a> </div> <h5 id="makeoval">makeOval</h5> <p>Scrawl-canvas uses quadratic curves internally to create the curved path. </p> <ul> <li>The <em>bend</em> of these curves is set by the quadratic’s control point which doesn’t have its own coordinate but is rather calculated using two float Number variables: <strong>offshootA</strong> (default: <code>0.55</code>) and <strong>offshootB</strong> (default: <code>0</code>) - change these values to make the quarter-curves more or less bendy.</li> <li>The main shape of the oval is determined by differing radius lengths in the <code>x</code> and <code>y</code> directions, as set by the attributes <strong>radiusX</strong> and <strong>radiusY</strong>; to set both radiuses to the same value, use <strong><strong>radius</strong></strong> instead.</li> <li>The radius values can be: <em>absolute</em> (using Number values); or <em>relative</em> using %-String values - with the y radius representing a portion of the Cell container’s height and the x radius the Cell’s width.</li> <li>The radiuses (as diameter lines) cross in the middle of the oval shape. We can move the position of where the intersection happens by setting a float Number value between <code>0.0 - 1.0</code> (or beyond those limits) for the <strong>intersectX</strong> and <strong>intersectY</strong> attributes. </li> <li><code>intersectX</code> (default: <code>0.5</code>) represents the point at which the <code>y</code> diameter crosses the <code>x</code> diameter, with <code>0</code> being the left end and <code>1</code> being the right end.</li> <li><code>intersectY</code> (default: <code>0.5</code>) represents the point at which the <code>x</code> diameter crosses the <code>y</code> diameter, with <code>0</code> being the top end and <code>1</code> being the bottom end.</li> </ul> <pre><code>scrawl.<span class="hljs-title function_">makeOval</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;egg&#x27;</span>, <span class="hljs-attr">fillStyle</span>: <span class="hljs-string">&#x27;lightGreen&#x27;</span>, <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;fillAndDraw&#x27;</span>, <span class="hljs-attr">startX</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">startY</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">radiusX</span>: <span class="hljs-string">&#x27;7%&#x27;</span>, <span class="hljs-attr">radiusY</span>: <span class="hljs-string">&#x27;3%&#x27;</span>, <span class="hljs-attr">intersectY</span>: <span class="hljs-number">0.6</span>, }); </code></pre> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> makeOval = <span class="hljs-keyword">function</span> (<span class="hljs-params">items</span>) { <span class="hljs-keyword">if</span> (!items) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; items.<span class="hljs-property">species</span> = <span class="hljs-string">&#x27;oval&#x27;</span>; <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span clas