-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvader.html
247 lines (221 loc) · 7.95 KB
/
vader.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Virtual Quantum Triple Slit Experiment </title>
<style>
body {
font-family: 'Times', sans-serif;
text-align: center;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
#canvasContainer {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
perspective: 800px; /* Adds a sense of depth to the canvas */
}
#canvas {
border: 1px solid black;
border-radius: 50%; /* Circular Canvas */
margin-top: 20px;
max-width: 400px;
max-height: 400px;
box-shadow: 10px 10px 30px rgba(0,0,0,0.5); /* Shadow for 3D effect */
transform: rotateX(45deg) rotateY(0deg); /* Tilt the canvas for 3D perspective */
}
button {
margin-top: 20px;
padding: 10px;
font-size: 16px;
}
#dieResult {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>Virtual Quantum Triple Slit Experiment</h1>
<div id="canvasContainer">
<canvas id="canvas" width="400" height="400"></canvas>
</div>
<div id="dieResult"></div>
<button onclick="initiateExperiment()">Start Experiment</button>
<button onclick="setObserverType('self-interested')">Self-Interested Observer</button>
<button onclick="setObserverType('neutral')">Neutral Observer</button>
<button onclick="setObserverType('selfless')">Selfless Observer</button>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let observerType = "neutral";
let currentTime = 0;
let amplitude = 1; // Default amplitude
let energy = 0.5; // Default energy
const electronMass = 1; // Placeholder value for electron mass
const protonMass = 1836; // Placeholder value for proton mass (about 1836 times electron mass)
const neutronMass = 1839; // Placeholder value for neutron mass (slightly more than proton)
function rollQuantumDie() {
const tritStates = ['electron', 'proton', 'neutron'];
let outcome = [];
for (let i = 0; i < 3; i++) {
const array = new Uint32Array(1);
window.crypto.getRandomValues(array);
outcome.push(tritStates[array[0] % tritStates.length]);
}
console.log("Quantum Die Outcome: " + outcome.join(', '));
return outcome;
}
function setObserverType(type) {
observerType = type;
console.log("Observer Type: " + observerType);
}
function initiateExperiment() {
const dieResult = rollQuantumDie();
displayDieResult(dieResult);
setTimeout(() => {
assembleTrits(dieResult);
setTimeout(startExperiment, 2000); // Delay to show trits assembling
}, 2000); // Delay to display die result
}
function displayDieResult(dieResult) {
document.getElementById('dieResult').innerText = "Quantum Die Rolled: " + dieResult.join(', ');
}
function assembleTrits(dieResult) {
let assemblyProgress = 0;
let assemblyInterval = setInterval(() => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawParticleBeams(assemblyProgress);
assemblyProgress += 2; // Adjust this value to change the speed of assembly
if (assemblyProgress >= canvas.width) {
clearInterval(assemblyInterval);
}
}, 20); // Time in milliseconds between updates
}
function drawParticleBeams(progress) {
const numberOfBeams = 10;
const particleSize = 5;
const spread = 50;
for (let i = 0; i < numberOfBeams; i++) {
let x = canvas.width / 2 + progress - spread / 2 + Math.random() * spread;
let y = canvas.height / 2 - progress - spread / 2 + Math.random() * spread;
ctx.beginPath();
ctx.arc(x, y, particleSize, 0, 2 * Math.PI);
ctx.fillStyle = `rgba(0, 150, 255, ${0.5 + Math.random() * 0.5})`;
ctx.fill();
}
}
function startExperiment() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
currentTime = 0;
requestAnimationFrame(updateExperiment);
}
function updateExperiment() {
currentTime += 0.05;
simulateParticles();
if (currentTime < 20) {
requestAnimationFrame(updateExperiment);
}
}
function simulateParticles() {
let tritOutcome = rollQuantumDie();
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawSlits();
for (let i = 0; i < 4000; i++) {
let particleState = tritOutcome[i % tritOutcome.length];
let { x, y } = getOrbitingPosition(particleState, i);
let slit = chooseSlit(x, y, tritOutcome);
let waveFunction = calculateWaveFunction(x, y, currentTime, slit, particleState);
drawParticle(x, y, waveFunction, particleState);
}
}
function getOrbitingPosition(state, index) {
let angle = (index / 4000) * 2 * Math.PI;
let distance;
switch (state) {
case 'electron':
distance = 50 + 10 * Math.sin(5 * angle);
break;
case 'proton':
distance = 70 + 10 * Math.cos(5 * angle);
break;
case 'neutron':
distance = 90 + 10 * Math.sin(10 * angle);
break;
default:
distance = 50;
}
let x = canvas.width /2 + distance * Math.cos(angle);
let y = canvas.height / 2 + distance * Math.sin(angle);
return { x, y };
}
function calculateWaveFunction(x, y, currentTime, slit, particleState) {
const hBar = 1;
let V = 0;
let k;
let waveFunction = 0;
switch (particleState) {
case 'electron':
k = Math.sqrt(2 * electronMass * (energy - V)) / hBar;
break;
case 'proton':
k = Math.sqrt(2 * protonMass * (energy - V)) / hBar;
break;
case 'neutron':
k = Math.sqrt(2 * neutronMass * (energy - V)) / hBar;
break;
}
waveFunction = amplitude * Math.sin(k * y + currentTime);
return waveFunction;
}
function drawSlits() {
for (let i = 1; i <= 3; i++) {
ctx.beginPath();
ctx.arc(canvas.width * i / 4, canvas.height / 2, 10, 0, 2 * Math.PI);
ctx.fillStyle = 'black';
ctx.fill();
}
}
function chooseSlit(x, y, tritOutcome) {
const slitRadius = 10;
const slit1Center = { x: canvas.width / 4, y: canvas.height / 2 };
const slit2Center = { x: canvas.width / 2, y: canvas.height / 2 };
const slit3Center = { x: 3 * canvas.width / 4, y: canvas.height / 2 };
if (isInsideCircle(x, y, slit1Center, slitRadius)) {
return 1;
} else if (isInsideCircle(x, y, slit2Center, slitRadius)) {
return 2;
} else if (isInsideCircle(x, y, slit3Center, slitRadius)) {
return 3;
} else {
return 0;
}
}
function isInsideCircle(x, y, center, radius) {
const distance = Math.sqrt((x - center.x) ** 2 + (y - center.y) ** 2);
return distance < radius;
}
function drawParticle(x, y, waveFunction, particleState) {
ctx.beginPath();
let particleSize = getParticleSize(waveFunction, particleState);
let color = getColorByState(particleState);
ctx.fillStyle = `rgba(${color.r}, ${color.g}, ${color.b}, 1)`;
ctx.arc(x, y, particleSize, 0, 2 * Math.PI);
ctx.fill();
}
function getParticleSize(waveFunction, particleState) {
return canvas.width / 200 + Math.abs(waveFunction) * 5;
}
function getColorByState(particleState) {
switch (particleState) {
case 'electron': return { r: 255, g: 0, b: 0 }; // Red for electrons
case 'proton': return { r: 0, g: 255, b: 0 }; // Green for protons
case 'neutron': return { r: 0, g: 0, b: 255 }; // Blue for neutrons
default: return { r: 128, g: 128, b: 128 }; // Default color
}
}
</script>
</body>
</html>