Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrustyPwo committed May 10, 2024
1 parent 901f3e0 commit bbda06c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions sim5.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<input type="range" min="20" max="80" step="10" value="50" class="slider" id="slitWidthInput">
Slit Width: <span id="slitWidthValue">50</span> px
</div>
<div class="slitSeparation">
<input type="range" min="50" max="200" step="10" value="100" class="slider" id="slitSeparationInput">
Slit Separation: <span id="slitSeparationValue">100</span> px
</div>
<div class="wavelength">
<input type="range" min="5" max="20" step="1" value="10" class="slider" id="wavelengthInput">
Wavelength: <span id="wavelengthValue">10</span> px
Expand Down
2 changes: 1 addition & 1 deletion static/js/sim4.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const c = cvs.getContext('2d');
const wavelengthInput = document.getElementById("wavelengthInput");
const slitWidthInput = document.getElementById("slitWidthInput");

const simulation = new RippleSimulation(cvs, c)
const simulation = new RippleSimulation(cvs, c, wavelengthInput.value, slitWidthInput.value);
const animate = () => {
c.clearRect(0, 0, cvs.width, cvs.height);
simulation.update();
Expand Down
6 changes: 6 additions & 0 deletions static/js/sim5.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const cvs = document.querySelector('canvas');
const c = cvs.getContext('2d');
const wavelengthInput = document.getElementById("wavelengthInput");
const slitWidthInput = document.getElementById("slitWidthInput");
const slitSeparationInput = document.getElementById("slitSeparationInput");

const simulation = new DoubleSlitSimulation(cvs, c)
const animate = () => {
Expand All @@ -27,5 +28,10 @@ slitWidthInput.oninput = () => {
simulation.setSlitWidth(slitWidthInput.value);
}

slitSeparationInput.oninput = () => {
document.getElementById("slitSeparationValue").innerText = slitSeparationInput.value;
simulation.setSlitSeparation(slitSeparationInput.value);
}


animate()
7 changes: 6 additions & 1 deletion static/js/simulations/doubleSlit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DoubleSlitSimulation extends Simulation {
for (let x = this.slit.x; x <= this.screen.x - 10; x += 5) {
for (let y = 0; y <= this.cvs.height; y += 5) {
const theta = Math.atan2(y - this.slit.y, x - this.slit.x);
this.c.globalAlpha = Math.min(1 * this.evaluate(theta), 255);
this.c.globalAlpha = Math.max(Math.min(1.5 * this.evaluate(theta), 1), 0.15);
const dist = distance(this.slit.x, this.slit.y, x, y);
this.c.fillStyle = interpolate(this.waveColor1, this.waveColor2, (1 + (Math.sin(dist / this.wavelength - 8 * this.t))) / 2);
this.c.fillRect(x, y, 3, 3);
Expand Down Expand Up @@ -72,6 +72,11 @@ class DoubleSlitSimulation extends Simulation {
this.cache = {};
}

setSlitSeparation = (slitSeparation) => {
this.slit.separation = slitSeparation;
this.cache = {};
}

mouseDown = (event) => {};

mouseUp = (event) => {};
Expand Down
6 changes: 3 additions & 3 deletions static/js/simulations/ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {distance} from "../utils/math.js";
import {Slit} from "../shared/slit.js";

class RippleSimulation extends Simulation {
constructor(cvs, c, wavelength = 20) {
constructor(cvs, c, wavelength = 10, slitWidth = 50) {
super(cvs, c);
this.wavelength = wavelength;
this.screen = new Screen(cvs, c, 0.85 * cvs.width, cvs.height / 2, cvs.height - 50);
this.slit = new Slit(cvs, c, 0.15 * cvs.width, cvs.height / 2, cvs.height - 50, 50);
this.slit = new Slit(cvs, c, 0.15 * cvs.width, cvs.height / 2, cvs.height - 50, slitWidth);

this.waveColor1 = "#ce2b15";
this.waveColor2 = "#000000";
Expand Down Expand Up @@ -39,7 +39,7 @@ class RippleSimulation extends Simulation {
for (let x = this.slit.x; x <= this.screen.x - 10; x += 5) {
for (let y = 0; y <= this.cvs.height; y += 5) {
const theta = Math.atan2(y - this.slit.y, x - this.slit.x);
this.c.globalAlpha = Math.min(10 * this.evaluate(theta), 255);
this.c.globalAlpha = Math.max(Math.min(10 * this.evaluate(theta), 1), 0.15);
const dist = distance(this.slit.x, this.slit.y, x, y);
this.c.fillStyle = interpolate(this.waveColor1, this.waveColor2, (1 + (Math.sin(dist / this.wavelength - 8 * this.t))) / 2);
this.c.fillRect(x, y, 3, 3);
Expand Down

0 comments on commit bbda06c

Please sign in to comment.