Added the rest of the files
This commit is contained in:
263
purcell.html
Normal file
263
purcell.html
Normal file
@@ -0,0 +1,263 @@
|
||||
<!--
|
||||
This work is licensed under CC BY-NC-ND 4.0
|
||||
Link to license: http://creativecommons.org/licenses/by-nc-nd/4.0/
|
||||
Attribute to Russell Georgi
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
Waves: Purcell
|
||||
</title>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
}
|
||||
|
||||
canvas {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.slideContainer {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#countdown {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
font-size: 150px;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;">
|
||||
Your browser does not support the HTML5 canvas tag.</canvas>
|
||||
<t id="countdown"></t>
|
||||
<div class="slidecontainer">
|
||||
<t>X</t>
|
||||
<input type="range" min="0" max="0.95" value="0.4" step = ".05" id="xSlider">
|
||||
<br>
|
||||
<t>Number of rays</t>
|
||||
<input type="range" min="10" max="50" value="20" step = "1" id="nSlider">
|
||||
<br>
|
||||
<t id="countdown"></t>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var c = document.getElementById("myCanvas");
|
||||
var ctx = c.getContext("2d");
|
||||
ctx.canvas.width = window.innerWidth;
|
||||
ctx.canvas.height = window.innerHeight;
|
||||
|
||||
var v = 0.4;
|
||||
var gaminv = Math.sqrt(1 - v ** 2);
|
||||
var rmax = 500;
|
||||
var n = 40;
|
||||
var scrwidth = c.width / 3;
|
||||
var dr = 1.5;
|
||||
var mm = 400 / dr;
|
||||
var dth = .01;
|
||||
var tg = 0;
|
||||
var theta = 0;
|
||||
var mInit = -120;
|
||||
var m = -100;
|
||||
var xPos = 0;
|
||||
var yPos = 0;
|
||||
var xSlider = document.getElementById("xSlider");
|
||||
|
||||
xSlider.oninput = function()
|
||||
{
|
||||
v = parseFloat(this.value);
|
||||
gaminv = Math.sqrt(1 - v ** 2);
|
||||
rmax = 500;
|
||||
m = mInit;
|
||||
}
|
||||
|
||||
nSlider.oninput = function()
|
||||
{
|
||||
n = parseFloat(this.value);
|
||||
}
|
||||
|
||||
function fnatn(s, c)
|
||||
{
|
||||
if (c > 0)
|
||||
{
|
||||
return Math.atan(s / c);
|
||||
}
|
||||
if (c == 0)
|
||||
{
|
||||
return Math.PI / 2;
|
||||
}
|
||||
if (c < 0)
|
||||
{
|
||||
return Math.PI - Math.atan(-s / c);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
|
||||
ctx.scale(1.5, -1.5);
|
||||
|
||||
function Clear(ctx)
|
||||
{
|
||||
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||
}
|
||||
|
||||
function Update()
|
||||
{
|
||||
Clear(ctx);
|
||||
Draw();
|
||||
m += 1;
|
||||
if (m < 0)
|
||||
{
|
||||
document.getElementById("countdown").textContent = (Math.ceil((-m) / 60)).toString();
|
||||
}
|
||||
if (m == 0)
|
||||
{
|
||||
document.getElementById("countdown").textContent = "";
|
||||
}
|
||||
setTimeout(Update, 1000/60);
|
||||
}
|
||||
|
||||
Update();
|
||||
|
||||
function Draw()
|
||||
{
|
||||
r = 0;
|
||||
tt = 5;
|
||||
if (m > 0)
|
||||
{
|
||||
r = m;
|
||||
}
|
||||
rp = r + tt;
|
||||
if (m < -tt)
|
||||
{
|
||||
rp = 0;
|
||||
}
|
||||
if (rp > rmax)
|
||||
{
|
||||
m = mInit;
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(v * r, 0);
|
||||
ctx.lineTo(rmax, 0);
|
||||
ctx.stroke();
|
||||
if ((n / 2) - Math.floor(n / 2) == 0)
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(v * r, 0);
|
||||
ctx.lineTo(-rmax, 0);
|
||||
ctx.stroke();
|
||||
}
|
||||
for (j = 1; j <= (n - 1) / 2; j++)
|
||||
{
|
||||
theta = 2 * Math.PI * j / n;
|
||||
cost = Math.cos(theta)
|
||||
sint = Math.sin(theta)
|
||||
costp = (cost + v) / (1 + v * cost)
|
||||
sintp = gaminv * sint / (1 + v * cost)
|
||||
thetap = fnatn(sintp, costp)
|
||||
ctx.strokeStyle = Colorify((j % 5) + 3);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + rp * cost, yPos + rp * sint);
|
||||
ctx.lineTo(xPos + rmax * cost, yPos + rmax * sint);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + v * r, yPos);
|
||||
ctx.lineTo(xPos + r * costp, yPos + r * sintp);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + rp * cost, yPos - rp * sint);
|
||||
ctx.lineTo(xPos + rmax * cost, yPos - rmax * sint);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + v * r, yPos);
|
||||
ctx.lineTo(xPos + r * costp, yPos - r * sintp);
|
||||
ctx.stroke();
|
||||
if (Math.abs(theta - thetap) > 0.001)
|
||||
{
|
||||
console.log(thetap);
|
||||
console.log(theta);
|
||||
for (thj = thetap; thj <= theta; thj += dth)
|
||||
{
|
||||
rr1 = r + tt * (thj - thetap) / (theta - thetap);
|
||||
rr2 = rr1 + tt * dth / (theta - thetap);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + rr1 * Math.cos(thj), yPos + rr1 * Math.sin(thj));
|
||||
ctx.lineTo(xPos + rr2 * Math.cos(thj + dth), yPos + rr2 * Math.sin(thj + dth));
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + rr1 * Math.cos(thj), yPos - rr1 * Math.sin(thj));
|
||||
ctx.lineTo(xPos + rr2 * Math.cos(thj + dth), yPos - rr2 * Math.sin(thj + dth));
|
||||
ctx.stroke();
|
||||
rr1 = rr2;
|
||||
}
|
||||
} else
|
||||
{
|
||||
console.log("No");
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + r * Math.cos(theta), yPos + r * Math.sin(theta));
|
||||
ctx.lineTo(xPos + rp * Math.cos(theta), yPos + rp * Math.sin(theta));
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + r * Math.cos(theta), yPos - r * Math.sin(theta));
|
||||
ctx.lineTo(xPos + rp * Math.cos(theta), yPos - rp * Math.sin(theta));
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('resize', function(event) {
|
||||
c.width = window.innerWidth;
|
||||
c.height = window.innerHeight;
|
||||
ctx.translate(c.width / 2, c.height / 2);
|
||||
ctx.scale(1.5, -1.5);
|
||||
}, true);
|
||||
|
||||
function Colorify(n)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
return "#000000"
|
||||
} else if (n == 1)
|
||||
{
|
||||
return "#0000aa"
|
||||
} else if (n == 2)
|
||||
{
|
||||
return "#00aa00"
|
||||
} else if (n == 3)
|
||||
{
|
||||
return "#00aaaa"
|
||||
} else if (n == 4)
|
||||
{
|
||||
return "#aa0000"
|
||||
} else if (n == 5)
|
||||
{
|
||||
return "#aa00aa"
|
||||
} else if (n == 6)
|
||||
{
|
||||
return "#aa5500"
|
||||
} else if (n == 7)
|
||||
{
|
||||
return "#aaaaaa"
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
<p xmlns:cc="http://creativecommons.org/ns#" style="font-size: 1vw; bottom: 0px; position: absolute;">
|
||||
This work is licensed under
|
||||
<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1"></a></p>
|
||||
</html>
|
||||
Reference in New Issue
Block a user