Files
WavesPrograms/10-3.html
2021-08-19 17:45:00 -07:00

153 lines
5.2 KiB
HTML

<!--
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 10-3
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
form {
position: relative;
}
</style>
</head>
<body>
<form>
<label for="ratio">k2 / k1</label>
<input type="number" id="ratio" name="ratio" min="0" max="10" step = "0.1" value = "1">
</form>
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
c.width = window.innerWidth;
c.height = window.innerHeight;
var k = 1;
var eps = parseFloat(document.getElementById("ratio").value);
var tau = 2 / (1 + eps);
var r = (1 - eps) / (1 + eps);
var kappa = .05;
var dt = .2 * (1 + eps);
var t = -30;
var nn = 40;
var m = 1;
var color1
var xPos = 0;
var yPos = -50;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
ctx.scale(4, -4);
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
if (parseFloat(document.getElementById("ratio").value) != eps)
{
eps = parseFloat(document.getElementById("ratio").value);
tau = 2 / (1 + eps);
r = (1 - eps) / (1 + eps);
kappa = .05;
dt = .2 * (1 + eps);
t = -30;
nn = 40;
}
Clear(ctx);
Draw();
t += dt;
if (eps <= 1)
{
if (t > 30)
{
t = -30;
}
}
if (eps > 1)
{
if (t > 30 * eps)
{
t = -30;
}
}
m += 1;
ctx.strokeStyle = "#000000";
setTimeout(Update, 1000/60)
}
function y(x)
{
if (kappa * x * x < 10)
{
return Math.exp(-kappa * x * x);
} else
{
return 0;
}
}
function Draw()
{
for (n = -nn/2; n <= -1; n++)
{
ctx.strokeStyle = "#ee0000";
ctx.beginPath();
ctx.moveTo(xPos + 100 * n / nn, yPos + 20 * (y(n - t) + r * y(-n -t)) + 50);
ctx.lineTo(xPos + 100 * (n + 1) / nn, yPos + 20 * (y(n + 1 - t) + r * y( - n - 1 - t)) + 50);
ctx.stroke();
}
if (eps == 0)
{
ctx.strokeStyle = "#9999ff";
ctx.beginPath();
ctx.moveTo(xPos, yPos + 20 * tau * y(-t) + 50);
ctx.lineTo(xPos + 50, yPos + 20 * tau * y(-t) + 50);
ctx.stroke();
} else
{
for (n = 0; n <= eps * nn / 2 - 1; n++)
{
ctx.strokeStyle = "#9999ff";
ctx.beginPath();
ctx.moveTo(xPos + 100 * n / nn / eps, yPos + 20 * tau * y(n-t) + 50);
ctx.lineTo(xPos + 100 * (n + 1) / nn / eps, yPos + 20 * tau * y((n + 1)-t) + 50);
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(4, -4);
}, true);
Update();
</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>