A Pen by Kyoya Baba on CodePen.
Created
June 22, 2019 05:04
-
-
Save qcgm1978/c7d985b956cb0b8b8da9815974d4c0f7 to your computer and use it in GitHub Desktop.
Double-slit experiment simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="jsi-canvas" class="g_canvas"> | |
<li></li> | |
<li></li> | |
<li></li> | |
<li></li> | |
<li></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $canvas = document.getElementById('jsi-canvas'); | |
setInterval(() => { | |
const $targets = $canvas.querySelectorAll('li'); | |
const positiveRand = Math.random() * 1; | |
const negativeRand = Math.random() * -1; | |
const indexRand = (positiveRand + negativeRand) * 3; | |
const targetIndex = parseInt(indexRand, 10) + 2; | |
$targets[targetIndex].insertAdjacentHTML( | |
'beforeend', | |
` | |
<div class="g_photon" | |
style=" | |
top: ${Math.random() * 100}%; | |
left: ${Math.random() * 100}%; | |
"> | |
</div> | |
` | |
); | |
}, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.g_canvas { | |
overflow: hidden; | |
display: flex; | |
justify-content: space-around; | |
width: 100vw; | |
height: 100vh; | |
background-color: #333333; | |
> li { | |
position: relative; | |
height: 100%; | |
&:nth-child(1), | |
&:nth-child(5) { | |
width: calc(10vw / 3); | |
} | |
&:nth-child(2), | |
&:nth-child(4) { | |
width: calc(10vw / 3 * 2); | |
} | |
&:nth-child(3) { | |
width: 10vw; | |
} | |
} | |
} | |
.g_photon { | |
position: absolute; | |
width: 1px; | |
height: 1px; | |
background-color: #FFFFFF; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment