UNPKG

scrawl-canvas

Version:
975 lines (616 loc) 41.5 kB
<!DOCTYPE html> <html> <head> <title>Pattern 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="pattern-factory">Pattern factory</h1> <p>Scrawl-canvas Pattern objects implement the Canvas API’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern">createPattern</a> method. The resulting <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern">CanvasPattern</a> object can be used by any Scrawl-canvas entity as its <code>fillStyle</code> or <code>strokeStyle</code>.</p> <ul> <li>Most pattern-related functionality has been coded up in the <a href="../mixin/styles.html">styles mixin</a>, and is documented there.</li> <li>Functionality associated with <strong>assets</strong>, which Patterns use as their source, has been coded up in the <a href="../mixin/assetConsumer.html">assetConsumer mixin</a>.</li> <li>Patterns fully participate in the Scrawl-canvas packet system, thus can be saved, restored, cloned, killed, etc.</li> <li>Patterns cannot be animated as such, but a Cell wrapper that is used as the Pattern’s source can be animated in any of the normal ways.</li> <li>Scrawl-canvas does not support the Canvas API <code>CanvasPattern.setTransform()</code> method - it appears to be based on the SVGMatrix interface, which was deprecated in the SVG2 standard.</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-009.html">Canvas-009</a> - Pattern styles; Entity web link anchors; Dynamic accessibility</li> <li><a href="../../demo/canvas-035.html">Canvas-035</a> - Pattern style functionality</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, cell, entity } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/library.js&#x27;</span>; <span class="hljs-keyword">import</span> { mergeOver, pushUnique, isa_obj, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../core/utilities.js&#x27;</span>; <span class="hljs-keyword">import</span> { stateKeys } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./state.js&#x27;</span>; <span class="hljs-keyword">import</span> { gettableVideoAssetAtributes, settableVideoAssetAtributes } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./videoAsset.js&#x27;</span>; <span class="hljs-keyword">import</span> { gettableImageAssetAtributes, settableImageAssetAtributes } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./imageAsset.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> patternMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/pattern.js&#x27;</span>; <span class="hljs-keyword">import</span> assetConsumerMix <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../mixin/assetConsumer.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> <h4 id="pattern-constructor">Pattern constructor</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">Pattern</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_">makeName</span>(items.<span class="hljs-property">name</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">register</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>); <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(items); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</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="pattern-prototype">Pattern prototype</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">Pattern</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;Pattern&#x27;</span>; P.<span class="hljs-property">lib</span> = <span class="hljs-string">&#x27;styles&#x27;</span>; P.<span class="hljs-property">isArtefact</span> = <span class="hljs-literal">false</span>; P.<span class="hljs-property">isAsset</span> = <span class="hljs-literal">false</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="mixins">Mixins</h4> </div> <div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P); P = <span class="hljs-title function_">patternMix</span>(P); P = <span class="hljs-title function_">assetConsumerMix</span>(P);</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="pattern-attributes">Pattern 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/pattern.html">pattern mixin</a>: <strong>repeat, patternMatrix, matrixA, matrixB, matrixC, matrixD, matrixE, matrixF</strong>.</li> <li>Attributes defined in the <a href="../mixin/assetConsumer.html">assetConsumer mixin</a>: <strong>asset, spriteTrack, imageSource, spriteSource, videoSource, source</strong>.</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = {}; 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-8"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-8">&#x00a7;</a> </div> <h4 id="packet-management">Packet management</h4> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">packetObjects</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetObjects</span>, [<span class="hljs-string">&#x27;asset&#x27;</span>]); P.<span class="hljs-property">finalizePacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">copy, items</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(items.<span class="hljs-property">patternMatrix</span>)) copy.<span class="hljs-property">patternMatrix</span> = items.<span class="hljs-property">patternMatrix</span>; <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> m = <span class="hljs-variable language_">this</span>.<span class="hljs-property">patternMatrix</span>; <span class="hljs-keyword">if</span> (m) copy.<span class="hljs-property">patternMatrix</span> = [m.<span class="hljs-property">a</span>, m.<span class="hljs-property">b</span>, m.<span class="hljs-property">c</span>, m.<span class="hljs-property">d</span>, m.<span class="hljs-property">e</span>, m.<span class="hljs-property">f</span>]; } <span class="hljs-keyword">return</span> copy; };</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="clone-management">Clone management</h4> <p>No additional clone 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="kill-management">Kill management</h4> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">kill</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">let</span> { name, asset, removeAssetOnKill } = <span class="hljs-variable language_">this</span>; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(asset)) asset.<span class="hljs-title function_">unsubscribe</span>(<span class="hljs-variable language_">this</span>);</pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-11">&#x00a7;</a> </div> <p>Remove style from all entity state objects</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">entries</span>(entity).<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">[label, ent]</span>) =&gt;</span> { <span class="hljs-keyword">let</span> state = ent.<span class="hljs-property">state</span>; <span class="hljs-keyword">if</span> (state) { <span class="hljs-keyword">let</span> fill = state.<span class="hljs-property">fillStyle</span>, stroke = state.<span class="hljs-property">strokeStyle</span>; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(fill) &amp;&amp; fill.<span class="hljs-property">name</span> === name) state.<span class="hljs-property">fillStyle</span> = state.<span class="hljs-property">defs</span>.<span class="hljs-property">fillStyle</span>; <span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_obj</span>(stroke) &amp;&amp; stroke.<span class="hljs-property">name</span> === name) state.<span class="hljs-property">strokeStyle</span> = state.<span class="hljs-property">defs</span>.<span class="hljs-property">strokeStyle</span>; } });</pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-12">&#x00a7;</a> </div> <p>Cascade kill invocation to the asset object, if required</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (removeAssetOnKill) { <span class="hljs-keyword">if</span> (removeAssetOnKill.<span class="hljs-property">substring</span>) asset.<span class="hljs-title function_">kill</span>(<span class="hljs-literal">true</span>); <span class="hljs-keyword">else</span> asset.<span class="hljs-title function_">kill</span>(); }</pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-13">&#x00a7;</a> </div> <p>Remove style from the Scrawl-canvas library</p> </div> <div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deregister</span>(); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-14">&#x00a7;</a> </div> <h4 id="get-set-deltaset">Get, Set, deltaSet</h4> <p>Pattern <code>get</code> and <code>set</code> (but not <code>deltaSet</code>) functions need to take into account their current source, whose attributes can be retrieved/amended directly on the Picture object</p> </div> </li> <li id="section-15"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-15">&#x00a7;</a> </div> <p><code>get</code></p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">get</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">let</span> source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>; <span class="hljs-keyword">if</span> ((item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">&#x27;video_&#x27;</span>) === <span class="hljs-number">0</span> || item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">&#x27;image_&#x27;</span>) === <span class="hljs-number">0</span>) &amp;&amp; source) { <span class="hljs-keyword">if</span> (gettableVideoAssetAtributes.<span class="hljs-title function_">indexOf</span>(item) &gt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> source[item.<span class="hljs-title function_">substring</span>(<span class="hljs-number">6</span>)]; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (gettableImageAssetAtributes.<span class="hljs-title function_">indexOf</span>(item) &gt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> source[item.<span class="hljs-title function_">substring</span>(<span class="hljs-number">6</span>)]; } <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> getter = <span class="hljs-variable language_">this</span>.<span class="hljs-property">getters</span>[item]; <span class="hljs-keyword">if</span> (getter) <span class="hljs-keyword">return</span> getter.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>); <span class="hljs-keyword">else</span> { <span class="hljs-keyword">let</span> def = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[item], val; <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> def != <span class="hljs-string">&#x27;undefined&#x27;</span>) { val = <span class="hljs-variable language_">this</span>[item]; <span class="hljs-keyword">return</span> (<span class="hljs-keyword">typeof</span> val != <span class="hljs-string">&#x27;undefined&#x27;</span>) ? val : def; } <span class="hljs-keyword">return</span> undef; } } };</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>set</code></p> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">set</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) { <span class="hljs-keyword">const</span> keys = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">keys</span>(items), keysLen = keys.<span class="hljs-property">length</span>; <span class="hljs-keyword">if</span> (keysLen) { <span class="hljs-keyword">const</span> setters = <span class="hljs-variable language_">this</span>.<span class="hljs-property">setters</span>, source = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>, defs = <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>; <span class="hljs-keyword">let</span> predefined, i, key, value; <span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; keysLen; i++) { key = keys[i]; value = items[key]; <span class="hljs-keyword">if</span> ((key.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">&#x27;video_&#x27;</span>) === <span class="hljs-number">0</span> || key.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">&#x27;image_&#x27;</span>) === <span class="hljs-number">0</span>) &amp;&amp; source) { <span class="hljs-keyword">if</span> (settableVideoAssetAtributes.<span class="hljs-title function_">indexOf</span>(key) &gt;= <span class="hljs-number">0</span>) source[key.<span class="hljs-title function_">substring</span>(<span class="hljs-number">6</span>)] = value <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (settableImageAssetAtributes.<span class="hljs-title function_">indexOf</span>(key) &gt;= <span class="hljs-number">0</span>) source[key.<span class="hljs-title function_">substring</span>(<span class="hljs-number">6</span>)] = value } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (key &amp;&amp; key !== <span class="hljs-string">&#x27;name&#x27;</span> &amp;&amp; value != <span class="hljs-literal">null</span>) { predefined = setters[key]; <span class="hljs-keyword">if</span> (predefined) predefined.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, value); <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> defs[key] !== <span class="hljs-string">&#x27;undefined&#x27;</span>) <span class="hljs-variable language_">this</span>[key] = value; } } <span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>; } <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>; };</pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-17">&#x00a7;</a> </div> <h4 id="prototype-functions">Prototype functions</h4> </div> </li> <li id="section-18"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-18">&#x00a7;</a> </div> <p><code>getData</code> function called by Cell objects when calculating required updates to its CanvasRenderingContext2D engine, specifically for an entity’s <strong>fillStyle</strong>, <strong>strokeStyle</strong> and <strong>shadowColor</strong> attributes.</p> <ul> <li>This is the point when we clean Scrawl-canvas assets which have told their subscribers that asset data/attributes have updated</li> </ul> </div> <div class="content"><div class='highlight'><pre>P.<span class="hljs-property">getData</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">entity, cell</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyAsset</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">cleanAsset</span>(); <span class="hljs-variable language_">this</span>.<span class="hljs-property">asset</span>.<span class="hljs-title function_">checkSource</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span>); <span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">buildStyle</span>(cell); };</pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-19">&#x00a7;</a> </div> <h4 id="factory">Factory</h4> <pre><code>scrawl.<span class="hljs-title function_">importDomImage</span>(<span class="hljs-string">&#x27;.mypatterns&#x27;</span>); scrawl.<span class="hljs-title function_">makePattern</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;brick-pattern&#x27;</span>, <span class="hljs-attr">asset</span>: <span class="hljs-string">&#x27;brick&#x27;</span>, }).<span class="hljs-title function_">clone</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;marble-pattern&#x27;</span>, <span class="hljs-attr">imageSource</span>: <span class="hljs-string">&#x27;img/marble.png&#x27;</span>, }); scrawl.<span class="hljs-title function_">makeBlock</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;marble-block&#x27;</span>, <span class="hljs-attr">width</span>: <span class="hljs-string">&#x27;40%&#x27;</span>, <span class="hljs-attr">height</span>: <span class="hljs-string">&#x27;40%&#x27;</span>, <span class="hljs-attr">startX</span>: <span class="hljs-string">&#x27;25%&#x27;</span>, <span class="hljs-attr">startY</span>: <span class="hljs-string">&#x27;25%&#x27;</span>, <span class="hljs-attr">handleX</span>: <span class="hljs-string">&#x27;center&#x27;</span>, <span class="hljs-attr">handleY</span>: <span class="hljs-string">&#x27;center&#x27;</span>, <span class="hljs-attr">lineWidth</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">lineJoin</span>: <span class="hljs-string">&#x27;round&#x27;</span>, <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;fillThenDraw&#x27;</span>, <span class="hljs-attr">fillStyle</span>: <span class="hljs-string">&#x27;marble-pattern&#x27;</span>, <span class="hljs-attr">strokeStyle</span>: <span class="hljs-string">&#x27;brick-pattern&#x27;</span>, }); </code></pre> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> makePattern = <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>; <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Pattern</span>(items); }; constructors.<span class="hljs-property">Pattern</span> = <span class="hljs-title class_">Pattern</span>;</pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-20">&#x00a7;</a> </div> <h4 id="exports">Exports</h4> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> { makePattern, };</pre></div></div> </li> </ul> </div> </body> </html>