scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
103 lines (82 loc) • 4.64 kB
HTML
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo Particles 008</title>
<link href="css/normalize.css" rel="stylesheet" />
<link href="css/tests.css" rel="stylesheet" />
<style>
.controls {
grid-template-columns: 1fr 2fr 1fr 2fr;
}
canvas {
margin: 0 auto;
}
img {
display: none;
}
</style>
</head>
<body>
<h1><a href="index.html">Scrawl-canvas v8</a> - Particles test 008</h1>
<h2>Net entity: generation and basic functionality, including Spring objects</h2>
<h3>Note that physics models can be a little tempramental!</h3>
<div class="controls">
<div class="green label">Net generate</div>
<div class="green">
<select class="controlItem" id="generate">
<option value="weak-net">weak-net</option>
<option value="strong-net">strong-net</option>
</select>
</div>
<div class="green label">Rest length (multiplier)</div>
<div class="green"><input class="controlItem" id="restLength" type="range" value="1" min="0.5" max="2" step="0.1" /></div>
<div class="green label">Spring constant</div>
<div class="green"><input class="controlItem" id="springConstant" type="range" value="50" min="5" max="300" step="5" /></div>
<div class="green label">Damper constant</div>
<div class="green"><input class="controlItem" id="damperConstant" type="range" value="5" min="5" max="50" step="1" /></div>
<div class="pink label">Particle mass</div>
<div class="pink"><input class="controlItem" id="mass" type="range" value="1" min="0.1" max="5" step="0.1" /></div>
<div class="pink label">Engine</div>
<div class="pink">
<select class="controlItem" id="engine">
<option value="euler">euler</option>
<option value="improved-euler">improved-euler</option>
<option value="runge-kutta">runge-kutta</option>
</select>
</div>
<div class="lavender label">Tick multiplier</div>
<div class="lavender"><input class="controlItem" id="tickMultiplier" type="range" value="2" min="0.5" max="3" step="0.05" /></div>
</div>
<canvas
id="mycanvas"
width="600"
height="400"
data-scrawl-canvas
data-base-background-color="aliceblue"
></canvas>
<p id="reportmessage"></p>
<div class="testinfo">
<h4>Test purpose</h4>
<ul>
<li>Create a particle world object; add a user-defined attribute ('wind') to it.</li>
<li>Create a wind Force, and a 'changeWind' function that updates the World.wind attribute at the start of each Display cycle.</li>
<li>Create a Net entity; set the 'columnDistance' attribute to a % String to make sure it will correctly convert it to a pixel distance. Set the 'generate' attribute to 'weak-net'; the 'forces' attribute to ['gravity', 'wind']; etc.</li>
<li>Include a 'postGenerate' function that will identify three specific particles, change their 'fill' and 'stroke' attributes to new colors, and go through the Scrawl-canvas scrawl.library.spring section to set the 'particleFromIsStatic' flag of all Spring objects associated with these Particles to true.</li>
<li>Confirm that the Net entity generates a mesh of particles, with three particles in the leftmost column displaying a different color, and not moving.</li>
<li>Check that particles respond to the gravity and wind forces appropriately (we are looking for a flapping sheet animation).</li>
<li>Check the effect of changing the Net attributes 'mass', 'springConstant', 'damperConstant' and 'restLength'.</li>
<li>Check the effect of changing the Net's 'engine' attribute - note that simulation failure is expected under various conditions (and is not a test failure).</li>
<li>Check the effect of changing the Net's 'generate' attribute</li>
<li>Navigate away from the web page (open another tab in the browser) and, a few seconds later, navigate back to the page - check that the animation resets and starts, and does not freeze the page</li>
</ul>
<p><b>Note:</b> The Safari browser is particularly sensitive to attempts to display images on Net entitys (using the Mesh entity) - the Demo most often works for this scenario when the tick multiplier attribute is reduced.</p>
<p><b>Touch test:</b> not required</p>
<p><a href="../docs/demo/particles-008.html">Annotated code</a></p>
</div>
<script src="particles-008.js" type="module"></script>
<img id="iris" src="img/iris.png" class="flowers" />
</body>
</html>