Skip to content

Commit

Permalink
Minor bug fixes and created game template in test
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePng committed Aug 13, 2024
1 parent b267a36 commit 216e87e
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/simulations/double_slit_diffraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="slitSeparation">
<input type="range" min="200" max="1000" step="100" value="500" class="slider" id="slitSeparationInput_DS">
Slit Separation: <span id="slitSeparationValue">500</span> μm
Slit Separation: <span id="slitSeparationValue_DS">500</span> μm
</div>
<div class="wavelength">
<input type="range" min="380" max="780" step="10" value="500" class="slider" id="wavelengthInput_DS">
Expand Down
27 changes: 15 additions & 12 deletions src/text/interference/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
## History Of Interference
In Ancient times, the concept of wave interference was not well understood, but early observations of light patterns can be traced back to ancient civilizations.

The understanding of interference began to take shape with the development of wave theory in the early 18th century, with the famous <b>Thomas Young's Double-Slit Experiment (1801)</b> showing the strange behaviours of light. While there were many mathematical approaches afterwards to calculate the interference patterns, it was only in the early 20th century that the concept of <b>particle wave duelity</b> slowly began to take shape.
The understanding of interference began to take shape with the development of wave theory in the early 18th century, with the famous **Thomas Young's Double-Slit Experiment (1801)** showing the strange behaviours of light. While there were many mathematical approaches afterwards to calculate the interference patterns, it was only in the early 20th century that the concept of **particle wave duelity** slowly began to take shape.

With that, more and more people started to accept the idea that small particles, such as the <b>Electron and Photons</b>, are able to exist in a superpositional state, both as a particle and a wave at the same time when unobserved.
With that, more and more people started to accept the idea that small particles, such as the **Electron and Photons**, are able to exist in a superpositional state, both as a particle and a wave at the same time when unobserved.

### Young's double slit experiment
Thomas Young, an English scientist, conducted his famous double-slit experiment to demonstrate the wave nature of light.
Expand All @@ -28,12 +28,12 @@ Similar experiments with photons (light particles) have shown that even single p
## Differences from Diffraction:
Interference shares many similarities with diffraction. But if so what makes it different?
### Difference in Mechanism
- Diffraction occurs when a <b>single</b> wave interacts with itself
- Interference occurs between <b>multiple</b> waves
- Diffraction occurs when a **single** wave interacts with itself
- Interference occurs between **multiple** waves

### Difference in Formula

1. **Interference** <br>
1. **Interference**
- Path Difference and Interference: <br>
$\delta = r_2 - r_1$

Expand Down Expand Up @@ -72,11 +72,14 @@ Interference shares many similarities with diffraction. But if so what makes it

## Theory and Formulae:

The <b>Principle of Superposition</b> states that when <b>TWO OR MORE</b> waves of the same kind overlap, the resultant displacement at any point at any instant is given by the <b>vector sum</b> of the <b>individual</b> displacements that each individual wave would cause at that point at that instant.
The **Principle of Superposition** states that when **TWO OR MORE** waves of the same kind overlap, the resultant displacement at any point at any instant is given by the **vector sum** of the **individual** displacements that each individual wave would cause at that point at that instant.

$y_{\text{resultant}} = y_1 + y_2 + y_3 + \dots + y_N$, where $y_{\text{resultant}}$ is the displacement of the resultant wave and $y_1, y_2, y_3 \dots, y_N$ are the individual displacements of the waves at the point of consideration
$$y_{\text{resultant}} = y_1 + y_2 + y_3 + \dots + y_N$$
Where
- $y_{\text{resultant}}$ is the displacement of the resultant wave and
- $y_1, y_2, y_3 \dots, y_N$ are the individual displacements of the waves at the point of consideration

Interference is the <b>superposing</b> of overlapping of <b>TWO OR MORE</b> waves to give a resultant wave whose displacement is given by the <b>Principle of Superposition</b>.
Interference is the **superposing** of overlapping of **TWO OR MORE** waves to give a resultant wave whose displacement is given by the **Principle of Superposition**.

### Path Difference
Path difference ($\delta$) is the difference in the optical path lengths traveled by two waves from their respective sources to a specific point where interference is observed. It directly affects the phase relationship between the waves at that point.
Expand Down Expand Up @@ -119,23 +122,23 @@ Phase Difference Δϕ = <span id="phaseDifference_2SF">0</span>π
<script type="module" src="../../javascript/sim2.js"></script>

### Constructive Interference
<b>Constructive interference</b> occurs when the waves that meet are in phase at the point of consideration.
**Constructive interference** occurs when the waves that meet are in phase at the point of consideration.

Phase difference between the two waves at that point = $0, 2\pi, 4\pi, \dots$

This happens under the following conditions: <br>
If $\delta = m \cdot \lambda$ (where $m$ is an integer), then the waves arrive at the point <b>in phase</b>, reinforcing each other. This leads to <b>constructive interference</b> and results in a <b>maximum amplitude</b> at that point.
If $\delta = m \cdot \lambda$ (where $m$ is an integer), then the waves arrive at the point **in phase**, reinforcing each other. This leads to **constructive interference** and results in a **maximum amplitude** at that point.

Resultant amplitude $A_R = A_1 + A_2$

### Destructive Interference

<b>Destructive interference</b> occurs when the waves that meet are in <b>in antiphase</b> (out of phase of difference 180 deg) at the point of consideration.
**Destructive interference** occurs when the waves that meet are in **in antiphase** (out of phase of difference 180 deg) at the point of consideration.

Phase difference between the two waves at that point = $\pi, 3\pi, 5\pi$ <br>

This occurs under the following condition: <br>
If $\delta = (m + \frac{1}{2}) \cdot \lambda$ (where $m$ is an integer), then the waves arrive <b>out of phase</b>, leading to cancellation of amplitudes. This results in <b>destructive interference</b> and a <b>minimum amplitude</b> (or even complete cancellation) at that point.
If $\delta = (m + \frac{1}{2}) \cdot \lambda$ (where $m$ is an integer), then the waves arrive **out of phase**, leading to cancellation of amplitudes. This results in **destructive interference** and a **minimum amplitude** (or even complete cancellation) at that point.

Resultant amplitude $A_R = A_1 - A_2$

Expand Down
72 changes: 72 additions & 0 deletions test/game/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
let score = 0;
let combo = 0;
let currentQuestionIndex = 0;

function loadQuestion() {
const questionElement = document.getElementById('question');
const optionContainers = document.querySelectorAll('.option-container');
const optionsElements = document.querySelectorAll('.option');

const currentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;

optionsElements.forEach((option, index) => {
option.textContent = currentQuestion.options[index];
option.style.backgroundColor = '#e0e0e0';
option.disabled = false;
});

optionContainers.forEach((container, index) => {
const imgElement = container.querySelector('.option-image');
imgElement.src = currentQuestion.images[index]; // Assuming you have an array of images in your question
imgElement.alt = `Option ${index + 1} Image`;
});

document.getElementById('explanation').classList.add('hidden');
document.getElementById('next-button').classList.add('hidden');
}

function checkAnswer(selectedOption) {
const options = document.querySelectorAll('.option');
const explanation = document.getElementById('explanation');
const currentQuestion = questions[currentQuestionIndex];

if (selectedOption === currentQuestion.correctAnswer) {
options[currentQuestion.correctAnswer - 1].style.backgroundColor = 'green';
combo += 1;
score += 100 + (100 * 25 * combo) / 100;
explanation.classList.add('hidden');
} else {
options.forEach((option, index) => {
if (index === currentQuestion.correctAnswer - 1) {
option.style.backgroundColor = 'green';
} else {
option.style.backgroundColor = 'red';
}
});
combo = 0;
explanation.textContent = currentQuestion.explanation;
explanation.classList.remove('hidden');
}

document.getElementById('score').textContent = `Score: ${Math.floor(score)}`;

// Disable all options after one is selected
options.forEach(option => option.disabled = true);

// Show the next question button
document.getElementById('next-button').classList.remove('hidden');
}

function nextQuestion() {
currentQuestionIndex += 1;
if (currentQuestionIndex < questions.length) {
loadQuestion();
} else {
document.getElementById('question-container').innerHTML = '<p>Congratulations! You have completed the quiz.</p>';
document.getElementById('next-button').classList.add('hidden');
}
}

// Directly call loadQuestion to initialize the first question
loadQuestion();
43 changes: 43 additions & 0 deletions test/game/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.quiz-container {
max-width: 600px;
margin: auto;
text-align: center;
font-family: Arial, sans-serif;
}

.options {
display: flex;
justify-content: space-around;
margin: 10px 0;
}

.option-container {
display: flex;
flex-direction: column;
align-items: center;
}

.option-image {
width: 100px; /* Adjust the size as needed */
height: 100px;
object-fit: cover;
margin-bottom: 10px;
}

.option {
padding: 10px 20px;
font-size: 16px;
background-color: #e0e0e0;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

.option:hover {
background-color: #d0d0d0;
}

.hidden {
display: none;
}
46 changes: 46 additions & 0 deletions test/game/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz Game</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="quiz-container">
<h1>Quiz Game</h1>
<div id="question-container">
<p id="question"></p>
<div class="options">
<div class="option-container">
<img class="option-image" src="" alt="Option 1 Image">
<button class="option" onclick="checkAnswer(1)"></button>
</div>
<div class="option-container">
<img class="option-image" src="" alt="Option 2 Image">
<button class="option" onclick="checkAnswer(2)"></button>
</div>
</div>
<div class="options">
<div class="option-container">
<img class="option-image" src="" alt="Option 3 Image">
<button class="option" onclick="checkAnswer(3)"></button>
</div>
<div class="option-container">
<img class="option-image" src="" alt="Option 4 Image">
<button class="option" onclick="checkAnswer(4)"></button>
</div>
</div>
</div>
<p id="explanation" class="hidden"></p>
<p id="score">Score: 0</p>
<button id="next-button" class="hidden" onclick="nextQuestion()">Next Question</button>
</div>

<!-- Background Music -->
<audio id="bgm" src="path/to/your/music.mp3" autoplay loop></audio>

<script src="question_bank.js"></script>
<script src="game.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/game/question_bank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const questions = [
{
question: "What is the capital of France?",
options: ["Berlin", "Madrid", "Paris", "Rome"],
images: ["path/to/berlin.jpg", "path/to/madrid.jpg", "path/to/paris.jpg", "path/to/rome.jpg"],
correctAnswer: 3,
explanation: "The correct answer is Paris, the capital city of France."
},
{
question: "Which planet is known as the Red Planet?",
options: ["Earth", "Mars", "Jupiter", "Saturn"],
images: ["path/to/earth.jpg", "path/to/mars.jpg", "path/to/jupiter.jpg", "path/to/saturn.jpg"],
correctAnswer: 2,
explanation: "Mars is known as the Red Planet due to its reddish appearance."
},
{
question: "Who wrote 'Romeo and Juliet'?",
options: ["William Shakespeare", "Charles Dickens", "Mark Twain", "Jane Austen"],
images: ["path/to/shakespeare.jpg", "path/to/dickens.jpg", "path/to/twain.jpg", "path/to/austen.jpg"],
correctAnswer: 1,
explanation: "William Shakespeare is the author of 'Romeo and Juliet'."
}
];
19 changes: 19 additions & 0 deletions test/game/todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
List of items to be completed
1. Create a question timer - around 2 mins long
2. Create question bank - can be randomly generated by code
- Randomly assigning the number of slits, wavelengths etc and ask them to guess
- Each Question has 4 options, one correct answer
3. Create a point system
- No combo: 100 point
- Combo formula: 100 * (100 + 25 * N)%, where N is the combo number
Combo 2: 100 * 150% = 150 pts
Combo 5: 100 * 225% = 225 pts
- Stars/tier system:
1 star(Novice): 500 pts
2 stars (Intermediate): 1000 pts
3 stars (Expert): 1500 pts
4 stars (Professional): 2000 pts
5 stars (Einstein): 2500 pts



0 comments on commit 216e87e

Please sign in to comment.