scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
945 lines (609 loc) • 40.7 kB
HTML
<html>
<head>
<title>World 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 …</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">§</a>
</div>
<h1 id="world-factory">World factory</h1>
<p>The Scrawl-canvas particle physics engine is a simple system designed to allow developers a way to add particle-based effects to their canvas animation scenes. The physics engine is built on top of the following components:</p>
<ul>
<li><a href="./particle.html">Particle objects</a>, which represent a 3-dimensional coordinate - based on a Scrawl-canvas <a href="./vector.html">Vector object</a> - and include a history of recent positions which we can use to determine how to display that particle on screen.</li>
<li><a href="./particleHistory.html">History arrays</a> which can be pooled (reused) to cut down on Array creation and distruction during the animation.</li>
<li><a href="./particleForce.html">Force objects</a> which define the general and occasional forces to be applied to each particle in the system as the animation progresses - a <strong>gravity</strong> force object is pre-defined by Scrawl-canvas.</li>
<li><a href="./particleSpring.html">Spring objects</a> used to define a constraint (connection) between two particles in a system.</li>
<li><a href="./particleWorld.html">World objects</a> where we can store attributes and values used by various objects; these attributes can be set up so that they will be inherited by clones of the World object. We can also influence the speed of the physics animation here.</li>
</ul>
<p>We do not have to handle particle generation and manipulation ourselves. Instead, Scrawl-canvas gives us three dedicated <strong>entitys</strong> which we use to add particle animation effects to the canvas scene. These entitys are:</p>
<ul>
<li><a href="./tracer.html">Tracer</a> - this entity generates a single non-recycled (in other words: long lasting) particle with a history, which we can use to display trace effects in the animation.</li>
<li><a href="./emitter.html">Emitter</a> - an entity which generates a stream of short-lived, recycled particles, each with its own history. Emitters are highly versatile entitys which can generate a wide range of effects.</li>
<li><a href="./net.html">Net</a> - a (generally) larger entity which uses both forces and springs to manage the animation of its non-recycled particles. Note that other artefacts can use Net particles as a reference for their own positioning.</li>
</ul>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="demos">Demos:</h4>
<ul>
<li><a href="../../demo/particles-001.html">particles-001</a> - Emitter entity, and Particle World, basic functionality</li>
<li><a href="../../demo/particles-002.html">particles-002</a> - Emitter using artefacts</li>
<li><a href="../../demo/particles-003.html">particles-003</a> - Position Emitter entity: start; pivot; mimic; path; mouse; drag-and-drop</li>
<li><a href="../../demo/particles-004.html">particles-004</a> - Emit particles along the length of a path</li>
<li><a href="../../demo/particles-005.html">particles-005</a> - Emit particles from inside an artefact’s area</li>
<li><a href="../../demo/particles-006.html">particles-006</a> - Fixed number of particles in a field; preAction and postAction functionality</li>
<li><a href="../../demo/particles-007.html">particles-007</a> - Particle Force objects: generation and functionality</li>
<li><a href="../../demo/particles-008.html">particles-008</a> - Net entity: generation and basic functionality, including Spring objects</li>
<li><a href="../../demo/particles-009.html">particles-009</a> - Net particles: drag-and-drop functionality</li>
<li><a href="../../demo/particles-010.html">particles-010</a> - Net entity: using a shape path as a net template</li>
<li><a href="../../demo/particles-012.html">particles-012</a> - Use Net entity particles as reference coordinates for other artefacts</li>
<li><a href="../../demo/canvas-040.html">canvas-040</a> - Trace out a Shape path over time</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</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">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { mergeOver, isa_fn, xt, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> { makeQuaternion } <span class="hljs-keyword">from</span> <span class="hljs-string">'./quaternion.js'</span>;
<span class="hljs-keyword">import</span> { makeVector } <span class="hljs-keyword">from</span> <span class="hljs-string">'./vector.js'</span>;
<span class="hljs-keyword">import</span> { makeCoordinate } <span class="hljs-keyword">from</span> <span class="hljs-string">'./coordinate.js'</span>;
<span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/base.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="world-constructor">World constructor</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">World</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-keyword">let</span> keytypes = items.<span class="hljs-property">keytypes</span> || {};
<span class="hljs-keyword">if</span> (!keytypes.<span class="hljs-property">gravity</span>) keytypes.<span class="hljs-property">gravity</span> = <span class="hljs-string">'Vector'</span>;
<span class="hljs-keyword">if</span> (!items.<span class="hljs-property">gravity</span>) items.<span class="hljs-property">gravity</span> = [<span class="hljs-number">0</span>, <span class="hljs-number">9.81</span>, <span class="hljs-number">0</span>];
<span class="hljs-keyword">if</span> (items.<span class="hljs-property">userAttributes</span>) {
items.<span class="hljs-property">userAttributes</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">att</span> =></span> {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">addAttribute</span>(att);
<span class="hljs-keyword">if</span> (att.<span class="hljs-property">type</span>) keytypes[att.<span class="hljs-property">key</span>] = att.<span class="hljs-property">type</span>;
});
}
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initializeAttributes</span>(keytypes);
<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">§</a>
</div>
<h4 id="world-prototype">World prototype</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">World</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">'World'</span>;
P.<span class="hljs-property">lib</span> = <span class="hljs-string">'world'</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">§</a>
</div>
<h4 id="mixins">Mixins</h4>
</div>
<div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P);</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<h4 id="world-attributes">World attributes</h4>
<ul>
<li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</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-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<p>x, y and z components of <strong>gravity</strong>, measured in meters/secondSquared (used in <code>gravity</code> force calculations)</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">gravity</span>: <span class="hljs-literal">null</span>,</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<p><strong>tickMultiplier</strong> - a positive float Number value. Larger values increase the physics effect - equivalent to speeding up the animation</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">tickMultiplier</span>: <span class="hljs-number">1</span>,</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<p><strong>keytypes</strong> - a Javascript object made up of <code>key:String</code> attributes. Used as part of the factory when generating worlds which use user-defined attributes that need to be Scrawl-canvas Quaternions, Vectors (like gravity) or Coordinates.</p>
<ul>
<li>the <code>key</code> should be the attribute’s name</li>
<li>the <code>value</code> should be a String - either <code>'Quaternion'</code>, <code>'Vector'</code> or <code>'Coordinate'</code>.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">keytypes</span>: <span class="hljs-literal">null</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-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
<p>No additional packet management functionality required</p>
</div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>No additional clone functionality required</p>
</div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</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-variable language_">this</span>.<span class="hljs-title function_">deregister</span>();
<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
};</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</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-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<p><strong>gravity</strong>, with pseudo-attributes <em>gravityX</em>, <em>gravityY</em>, <em>gravityZ</em></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">gravityX</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span> && <span class="hljs-title function_">xt</span>(item)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span>.<span class="hljs-title function_">setX</span>(item); };
S.<span class="hljs-property">gravityY</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span> && <span class="hljs-title function_">xt</span>(item)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span>.<span class="hljs-title function_">setY</span>(item); };
S.<span class="hljs-property">gravityZ</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span> && <span class="hljs-title function_">xt</span>(item)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span>.<span class="hljs-title function_">setZ</span>(item); };
S.<span class="hljs-property">gravity</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span> && <span class="hljs-title function_">xt</span>(item)) <span class="hljs-variable language_">this</span>.<span class="hljs-property">gravity</span>.<span class="hljs-title function_">set</span>(item); };</pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</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">§</a>
</div>
<p><code>addAttribute</code>, <code>removeAttribute</code> - we can use these functions to add and remove other attributes to the World object. See the following Demos for examples of constructing a World object and adding attributes to it: </p>
<ul>
<li><a href="../../demo/particles-007.html">particles-007</a> Particle Force objects: generation and functionality; and </li>
<li><a href="../../demo/particles-008.html">particles-008</a> Net entity: generation and basic functionality, including Spring objects.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">addAttribute</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {
<span class="hljs-keyword">let</span> {key, defaultValue, setter, deltaSetter, getter} = items;
<span class="hljs-keyword">if</span> (key && key.<span class="hljs-property">substring</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[key] = <span class="hljs-title function_">xt</span>(defaultValue) ? defaultValue : <span class="hljs-literal">null</span>;
<span class="hljs-variable language_">this</span>[key] = <span class="hljs-title function_">xt</span>(defaultValue) ? defaultValue : <span class="hljs-literal">null</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_fn</span>(setter)) S[key] = setter;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_fn</span>(deltaSetter)) D[key] = deltaSetter;
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">isa_fn</span>(getter)) G[key] = getter;
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};
P.<span class="hljs-property">removeAttribute</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">key</span>) {
<span class="hljs-keyword">if</span> (key && key.<span class="hljs-property">substring</span>) {
<span class="hljs-keyword">delete</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>[key];
<span class="hljs-keyword">delete</span> <span class="hljs-variable language_">this</span>[key];
<span class="hljs-keyword">delete</span> G[key];
<span class="hljs-keyword">delete</span> S[key];
<span class="hljs-keyword">delete</span> D[key];
}
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<p><code>initializeAttributes</code> - internal function called by the constructor.</p>
</div>
<div class="content"><div class='highlight'><pre>P.<span class="hljs-property">initializeAttributes</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">types</span>) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> [key, value] <span class="hljs-keyword">of</span> <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">entries</span>(types)) {
<span class="hljs-keyword">switch</span> (value) {
<span class="hljs-keyword">case</span> <span class="hljs-string">'Quaternion'</span> :
<span class="hljs-variable language_">this</span>[key] = <span class="hljs-title function_">makeQuaternion</span>();
<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">case</span> <span class="hljs-string">'Vector'</span> :
<span class="hljs-variable language_">this</span>[key] = <span class="hljs-title function_">makeVector</span>();
<span class="hljs-keyword">break</span>;
<span class="hljs-keyword">case</span> <span class="hljs-string">'Coordinate'</span> :
<span class="hljs-variable language_">this</span>[key] = <span class="hljs-title function_">makeCoordinate</span>();
<span class="hljs-keyword">break</span>;
}
}
};</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<h4 id="factory">Factory</h4>
<pre><code>scrawl.<span class="hljs-title function_">makeWorld</span>({
<span class="hljs-attr">name</span>: <span class="hljs-string">'demo-world'</span>,
<span class="hljs-attr">tickMultiplier</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">userAttributes</span>: [
{
<span class="hljs-attr">key</span>: <span class="hljs-string">'testCoordinate'</span>,
<span class="hljs-attr">type</span>: <span class="hljs-string">'Coordinate'</span>,
<span class="hljs-attr">getter</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) { <span class="hljs-keyword">return</span> [].<span class="hljs-title function_">concat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">testCoordinate</span>) },
<span class="hljs-attr">setter</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">testCoordinate</span>.<span class="hljs-title function_">set</span>(item) },
},
{
<span class="hljs-attr">key</span>: <span class="hljs-string">'particleColor'</span>,
<span class="hljs-attr">defaultValue</span>: <span class="hljs-string">'#F0F8FF'</span>,
},
],
<span class="hljs-attr">testCoordinate</span>: [<span class="hljs-number">100</span>, <span class="hljs-number">100</span>],
});
</code></pre>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> makeWorld = <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_">World</span>(items);
};
constructors.<span class="hljs-property">World</span> = <span class="hljs-title class_">World</span>;</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<h4 id="exports">Exports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> {
makeWorld,
};</pre></div></div>
</li>
</ul>
</div>
</body>
</html>