UNPKG

scrawl-canvas

Version:
1,047 lines (670 loc) 65.3 kB
<!DOCTYPE html> <html> <head> <title>Crescent 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="crescent-factory">Crescent factory</h1> <p>Crescent entitys are formed by the intersection of two circles, rendered onto a DOM &lt;canvas&gt; element using the Canvas 2D API’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/Path2D">Path2D interface</a> - specifically the arc() method.</p> <ul> <li>Positioning functionality for the Crescent is supplied by the <strong>position</strong> mixin, while rendering functionality comes from the <strong>entity</strong> mixin. </li> <li>Crescent dimensions are tied closely to its <strong>radius</strong> attribute; relative dimensions are calculated using the Crescent’s Cell container’s width.</li> <li>Crescents 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 animated directly, or using delta animation, or act as the target for <strong>Tween</strong> animations.</li> <li>Crescents 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="demos">Demos:</h4> <ul> <li><a href="../../demo/canvas-055.html">Canvas-055</a> - TODO</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="imports">Imports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors, radian } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, xt, xto, xta, isa_number, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> { requestCoordinate, releaseCoordinate } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./coordinate.js&#x27;</span>; <span class="hljs-keyword">import</span> { requestCell, releaseCell } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./cell.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> entityMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/entity.js&#x27;</span>;</pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-4">&#x00a7;</a> </div> <p><strong>ensureFloat</strong> - return the value provided as a floating point number of given precision; return 0 if not a number</p> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title function_">ensureFloat</span> = (<span class="hljs-params">val, precision</span>) =&gt; { val = <span class="hljs-built_in">parseFloat</span>(val); <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">isa_number</span>(val)) val = <span class="hljs-number">0</span>; <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">isa_number</span>(precision)) precision = <span class="hljs-number">0</span>; <span class="hljs-keyword">return</span> <span class="hljs-built_in">parseFloat</span>(val.<span class="hljs-title function_">toFixed</span>(precision)); };</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="crescent-constructor">Crescent constructor</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Crescent</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">xto</span>(items.<span class="hljs-property">dimensions</span>, items.<span class="hljs-property">width</span>, items.<span class="hljs-property">height</span>, items.<span class="hljs-property">radius</span>)) items.<span class="hljs-property">radius</span> = <span class="hljs-number">5</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">entityInit</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="crescent-prototype">Crescent prototype</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Crescent</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;Crescent&#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/entity.html">entity</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_">entityMix</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="crescent-attributes">Crescent 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> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</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> <p><strong>outerRadius</strong>, <strong>innerRadius</strong> - the circles’ radius measured in Number pixels, or as a String% - <code>&#39;10%&#39;</code> - of the Cell’s width</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-attr">outerRadius</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">innerRadius</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">displacement</span>: <span class="hljs-number">0</span>, <span class="hljs-attr">displayIntersect</span>: <span class="hljs-literal">false</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-10"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-10">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> <p>No additional packet 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="clone-management">Clone management</h4> <p>No additional clone 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="kill-management">Kill management</h4> <p>No additional kill functionality required</p> </div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#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> G = P.<span class="hljs-property">getters</span>, S = P.<span class="hljs-property">setters</span>, D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <p><strong>width</strong> and <strong>height</strong> (and dimensions) values are largely irrelevant to Crescent entitys; they get used internally purely as part of the Display cycle stamp functionality. </p> </div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</a> </div> <p>If they are used to (delta)set the entity’s values then outerRadius will be set to the supplied width value with String% values calculated from the entity’s host’s width, while innerRadius will be set to the supplied height value with String% values calculated from the entity’s host’s height</p> </div> <div class="content"><div class='highlight'><pre>S.<span class="hljs-property">outerRadius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerRadius</span> = val; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; D.<span class="hljs-property">outerRadius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerRadius</span> = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">outerRadius</span>, val); <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; S.<span class="hljs-property">innerRadius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerRadius</span> = val; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; D.<span class="hljs-property">innerRadius</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerRadius</span> = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">innerRadius</span>, val); <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; S.<span class="hljs-property">width</span> = S.<span class="hljs-property">outerRadius</span>; D.<span class="hljs-property">width</span> = D.<span class="hljs-property">outerRadius</span>; S.<span class="hljs-property">height</span> = S.<span class="hljs-property">innerRadius</span>; D.<span class="hljs-property">height</span> = D.<span class="hljs-property">innerRadius</span>; S.<span class="hljs-property">displacement</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span> &amp;&amp; val.<span class="hljs-property">toFixed</span> &amp;&amp; val &gt;= <span class="hljs-number">0</span>) { <span class="hljs-keyword">let</span> d = val; <span class="hljs-keyword">if</span> (d &lt; <span class="hljs-number">0</span>) d = <span class="hljs-number">0</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">displacement</span> = d; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; D.<span class="hljs-property">displacement</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-keyword">if</span> (val != <span class="hljs-literal">null</span> &amp;&amp; val.<span class="hljs-property">toFixed</span>) { <span class="hljs-keyword">let</span> d = <span class="hljs-title function_">addStrings</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">displacement</span>, val); <span class="hljs-keyword">if</span> (d.<span class="hljs-property">toFixed</span> &amp;&amp; d &lt; <span class="hljs-number">0</span>) d = <span class="hljs-number">0</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">displacement</span> = d; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyDimensions</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } }; S.<span class="hljs-property">displayIntersect</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">displayIntersect</span> = val; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">true</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; };</pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-16">&#x00a7;</a> </div> <h4 id="prototype-functions">Prototype functions</h4> </div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <p>Dimensions calculations - overwrites mixin/position.js function</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">cleanDimensionsAdditionalActions</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">const</span> { <span class="hljs-attr">outerRadius</span>:oR, <span class="hljs-attr">innerRadius</span>:iR, <span class="hljs-attr">displacement</span>:disp } = <span class="hljs-variable language_">this</span>; <span class="hljs-keyword">let</span> host = <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">getHost</span>(), hostDims; <span class="hljs-keyword">if</span> (host) hostDims = (host.<span class="hljs-property">currentDimensions</span>) ? host.<span class="hljs-property">currentDimensions</span> : [host.<span class="hljs-property">w</span>, host.<span class="hljs-property">h</span>]; <span class="hljs-keyword">else</span> hostDims = [<span class="hljs-number">300</span>, <span class="hljs-number">150</span>]; <span class="hljs-keyword">let</span> [w, h] = hostDims; <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentOuterRadius</span> = (oR.<span class="hljs-property">substring</span>) ? (<span class="hljs-built_in">parseFloat</span>(oR) / <span class="hljs-number">100</span>) * w : oR; <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentInnerRadius</span> = (iR.<span class="hljs-property">substring</span>) ? (<span class="hljs-built_in">parseFloat</span>(iR) / <span class="hljs-number">100</span>) * h : iR; <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDisplacement</span> = (disp.<span class="hljs-property">substring</span>) ? (<span class="hljs-built_in">parseFloat</span>(disp) / <span class="hljs-number">100</span>) * w : disp; <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDimensions</span>[<span class="hljs-number">0</span>] = <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDimensions</span>[<span class="hljs-number">1</span>] = <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentOuterRadius</span> * <span class="hljs-number">2</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">true</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><code>calculateInterception</code> - internal function to calculate how the two circles interact</p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">calculateInterception</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">xta</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">currentOuterRadius</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentInnerRadius</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">currentDisplacement</span>)) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">cleanDimensionsAdditionalActions</span>(); <span class="hljs-keyword">const</span> { <span class="hljs-attr">currentOuterRadius</span>:oR, <span class="hljs-attr">currentInnerRadius</span>:iR, <span class="hljs-attr">currentDisplacement</span>:disp } = <span class="hljs-variable language_">this</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerCircleStart</span> = <span class="hljs-number">0</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerCircleEnd</span> = <span class="hljs-number">360</span> * radian; <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerCircleStart</span> = <span class="hljs-number">0</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerCircleEnd</span> = <span class="hljs-number">360</span> * radian; <span class="hljs-variable language_">this</span>.<span class="hljs-property">drawOuterCircle</span> = <span class="hljs-literal">false</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">drawDonut</span> = <span class="hljs-literal">false</span>; <span class="hljs-keyword">let</span> dMax = oR + iR, dMin = oR - iR; <span class="hljs-keyword">let</span> equalCircles = (!dMin) ? <span class="hljs-literal">true</span> : <span class="hljs-literal">false</span>; <span class="hljs-keyword">if</span> (equalCircles &amp;&amp; !disp) <span class="hljs-variable language_">this</span>.<span class="hljs-property">drawOuterCircle</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">else</span> { <span class="hljs-keyword">if</span> (disp &gt;= dMax) <span class="hljs-variable language_">this</span>.<span class="hljs-property">drawOuterCircle</span> = <span class="hljs-literal">true</span>; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (disp &lt; dMax &amp;&amp; disp &gt; dMin) { <span class="hljs-keyword">let</span> cell = <span class="hljs-title function_">requestCell</span>(); <span class="hljs-keyword">let</span> {engine, element} = cell; <span class="hljs-keyword">let</span> v = <span class="hljs-title function_">requestCoordinate</span>(), a, b;</pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <p>Decided to calculate the start/end angles for each circle through brute force</p> <ul> <li>Trigonometry is the proper answer, but I can’t get the equations to stay still and play nicely</li> <li>So instead we draw circles on a canvas and rotate a vector to see when it enters/leaves the circles</li> </ul> </div> <div class="content"><div class='highlight'><pre> element.<span class="hljs-property">width</span> = element.<span class="hljs-property">width</span>; engine.<span class="hljs-property">fillStyle</span> = <span class="hljs-string">&#x27;black&#x27;</span>; engine.<span class="hljs-title function_">save</span>(); engine.<span class="hljs-title function_">beginPath</span>(); engine.<span class="hljs-title function_">arc</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, oR, <span class="hljs-number">0</span>, <span class="hljs-title class_">Math</span>.<span class="hljs-property">PI</span> * <span class="hljs-number">2</span>); v.<span class="hljs-title function_">setFromArray</span>([iR, <span class="hljs-number">0</span>]); <span class="hljs-keyword">for</span> (a = <span class="hljs-number">0</span>; a &lt; <span class="hljs-number">360</span>; a += <span class="hljs-number">0.5</span>) { v.<span class="hljs-title function_">rotate</span>(<span class="hljs-number">0.5</span>); <span class="hljs-keyword">if</span>(engine.<span class="hljs-title function_">isPointInPath</span>(v[<span class="hljs-number">0</span>] + disp, v[<span class="hljs-number">1</span>])) <span class="hljs-keyword">break</span>; } engine.<span class="hljs-title function_">restore</span>(); engine.<span class="hljs-title function_">save</span>(); engine.<span class="hljs-title function_">beginPath</span>(); engine.<span class="hljs-title function_">arc</span>(disp, <span class="hljs-number">0</span>, iR, <span class="hljs-number">0</span>, <span class="hljs-title class_">Math</span>.<span class="hljs-property">PI</span> * <span class="hljs-number">2</span>); v.<span class="hljs-title function_">setFromArray</span>([oR, <span class="hljs-number">0</span>]); <span class="hljs-keyword">for</span> (b = <span class="hljs-number">0</span>; b &lt; <span class="hljs-number">360</span>; b += <span class="hljs-number">0.5</span>) { v.<span class="hljs-title function_">rotate</span>(<span class="hljs-number">0.5</span>); <span class="hljs-keyword">if</span>(!engine.<span class="hljs-title function_">isPointInPath</span>(...v)) <span class="hljs-keyword">break</span>; } engine.<span class="hljs-title function_">restore</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerCircleStart</span> = -b * radian; <span class="hljs-variable language_">this</span>.<span class="hljs-property">outerCircleEnd</span> = b * radian; <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerCircleStart</span> = a * radian; <span class="hljs-variable language_">this</span>.<span class="hljs-property">innerCircleEnd</span> = -a * radian; <span class="hljs-title function_">releaseCoordinate</span>(v); <span class="hljs-title function_">releaseCell</span>(cell); } <span class="hljs-keyword">else</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">drawDonut</span> = <span class="hljs-literal">true</span>; } };</pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <p>Calculate the Crescent entity’s <strong>Path2D object</strong></p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">cleanPathObject</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyPathObject</span> = <span class="hljs-literal">false</span>; <span class="hljs-keyword">if</span> (!<span class="hljs-variable language_">this</span>.<span class="hljs-property">noPathUpdates</span> || !<span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObject</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">calculateInterception</span>(); <span class="hljs-keyword">let</span> { <span class="hljs-attr">currentStampHandlePosition</span>:handle, <span class="hljs-attr">currentScale</span>:scale, <span class="hljs-attr">currentOuterRadius</span>:oR, <span class="hljs-attr">currentInnerRadius</span>:iR, <span class="hljs-attr">outerCircleStart</span>:ocs, <span class="hljs-attr">outerCircleEnd</span>:oce, <span class="hljs-attr">innerCircleStart</span>:ics, <span class="hljs-attr">innerCircleEnd</span>:ice, drawOuterCircle, <span class="hljs-attr">currentDisplacement</span>:disp, displayIntersect } = <span class="hljs-variable language_">this</span>; <span class="hljs-keyword">let</span> p = <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObject</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path2</span>D(); oR *= scale; iR *= scale; disp *= scale; <span class="hljs-keyword">let</span> x = oR - (handle[<span class="hljs-number">0</span>] * scale), y = oR - (handle[<span class="hljs-number">1</span>] * scale); <span class="hljs-keyword">if</span> (drawOuterCircle) { p.<span class="hljs-title function_">arc</span>(x, y, oR, ocs, oce); p.<span class="hljs-title function_">closePath</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObjectOuter</span> = <span class="hljs-literal">false</span>; <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObjectInner</span> = <span class="hljs-literal">false</span>; } <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> pOuter = <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObjectOuter</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path2</span>D(); <span class="hljs-keyword">let</span> pInner = <span class="hljs-variable language_">this</span>.<span class="hljs-property">pathObjectInner</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path2</span>D(); <span class="hljs-keyword">if</span> (displayIntersect) p.<span class="hljs-title function_">arc</span>(x, y, oR, ocs, oce); <span class="hljs-keyword">else</span> p.<span class="hljs-title function_">arc</span>(x, y, oR, ocs, oce, <span class="hljs-literal">true</span>); p.<span class="hljs-title function_">arc</span>(x + disp, y, iR, ics, ice); p.<span class="hljs-title function_">closePath</span>(); pOuter.<span class="hljs-title function_">arc</span>(x, y, oR, ocs, oce, <span class="hljs-literal">true</span>); pOuter.<span class="hljs-title function_">closePath</span>(); pInner.<span cl