diff options
| author | 2023-10-11 19:05:35 +0000 | |
|---|---|---|
| committer | 2023-10-11 19:05:35 +0000 | |
| commit | b731627c6221cd88dafb1e7c0d54f85c5e2c316b (patch) | |
| tree | 16bea88be89ca61122390f9090860bcfe0d3c824 | |
| parent | culling spherical waves from atoms (diff) | |
add buttons to clear atoms and waves
| -rw-r--r-- | index.html | 17 | ||||
| -rw-r--r-- | scattering.js | 31 |
2 files changed, 43 insertions, 5 deletions
@@ -6,10 +6,21 @@ <meta charset="utf-8"> </head> <body> -This page and the associated code is GNU GPL v3.0 or later. This page is + <script src="scattering.js"></script> +<p>Plane wave scattering simulation by Peter McGoron</p> +<p>This page and the associated code is GNU GPL v3.0 or later. This page is distributed <b>WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</b> See the GNU -GPL for more details. - <script src="scattering.js"></script> +GPL for more details. <a href="https://software.mcgoron.com/peter/scattering.js">Code</a></p> +<p>Things to try: +<ul> +<li>Send a wave at an angle to the lattice.</li> +<li>Send a bunch of waves to the lattice at once.</li> +<li>Send a bunch of waves to the lattice, but slowly. </li> +</ul> +For each case, what do the wavefronts look like? +</p> +<button id="clear_waves">Clear waves</button> +<button id="clear_atoms">Clear atoms</button> </body> </html> diff --git a/scattering.js b/scattering.js index 732e8d8..536896c 100644 --- a/scattering.js +++ b/scattering.js @@ -443,6 +443,9 @@ class SimulationMouseHandler extends MouseHandler { handleMouse() { var r; + if (mouseX < 0 || mouseX > width || mouseY < 0 || mouseY > height) + return null; + if (mouseIsPressed && !this.mouseDown) { this.mouseDown = true; r = this[this.state].handleMouseDown(); @@ -472,6 +475,29 @@ class Simulation { this.atomTree = new AABBNode(); this.atoms = []; this.mouseHandler = new SimulationMouseHandler(); + + const _this = this; + document.getElementById("clear_waves").addEventListener("click", function (e) { + _this.planeWaves = []; + _this.sphericalWaves = []; + }); + document.getElementById("clear_atoms").addEventListener("click", function (e) { + _this.atoms = []; + _this.atomTree = new AABBNode(); + }); + } + + addAtom(atom) { + this.atomTree.add(atom, atom.boundRect); + this.atoms.push(atom); + } + + bragg_setup() { + for (let x = 50; x < width; x += 50) { + for (let y = height - 200; y < height; y += 50) { + this.addAtom(new Atom(x, y)); + } + } } update() { @@ -479,8 +505,7 @@ class Simulation { if (handleRet instanceof PlaneWave) { this.planeWaves.push(handleRet); } else if (handleRet instanceof Atom) { - this.atomTree.add(handleRet, handleRet.boundRect); - this.atoms.push(handleRet); + this.addAtom(handleRet); } for (let ind = 0; ind < this.planeWaves.length; ind++) { @@ -518,10 +543,12 @@ class Simulation { var sim; function setup() { + frameRate(30); createCanvas(800, 600); fill(0); sim = new Simulation(); + sim.bragg_setup(); } function draw() { |
