126 lines
4.5 KiB
HTML
126 lines
4.5 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 6-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>
|
|
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;"></canvas>
|
|
<form>
|
|
<label for="w">w</label>
|
|
<input type="number" id="w" name="w" min="0.1" max="0.9" step = "0.1" value="0.5">
|
|
<br>
|
|
<label for="nTerms">Number of terms</label>
|
|
<input type="number" id="nTerms" name="nTerms" min="1" max="20" step = "1" value = "1">
|
|
</form>
|
|
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
var k = 1;
|
|
var w = document.getElementById("w").value;
|
|
var a0 = 40
|
|
var nn = 400;
|
|
var nterms = document.getElementById("nTerms").value;
|
|
var mm0 = 16;
|
|
var psi = new Array(nn);
|
|
var m = 1;
|
|
var xPos = -100;
|
|
var yPos = -75;
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(3, -3);
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
w = parseFloat(document.getElementById("w").value);
|
|
if (w <= 0)
|
|
{
|
|
w = 0.1;
|
|
document.getElementById("w").value = 0.1;
|
|
} else if (w >= 1)
|
|
{
|
|
w = 0.9;
|
|
document.getElementById("w").value = 0.9;
|
|
}
|
|
nterms = parseFloat(document.getElementById("nTerms").value);
|
|
if (nterms < 1)
|
|
{
|
|
nterms = 1;
|
|
document.getElementById("nTerms").value = 1;
|
|
} else if (nterms > 20)
|
|
{
|
|
nterms = 20;
|
|
document.getElementById("nTerms").value = 20;
|
|
}
|
|
Clear(ctx);
|
|
Draw();
|
|
ctx.strokeStyle = "#000000";
|
|
setTimeout(Update, 1000/60)
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
for (n = 0; n <= nn; n++)
|
|
{
|
|
psi[n] = 0;
|
|
for (k = 1; k < nterms + 1; k++)
|
|
{
|
|
psi[n] += Math.sin(w*k*Math.PI) / k / k * Math.sin(k*n*Math.PI/nn) * Math.cos(m*k/mm0);
|
|
}
|
|
psi[n] = psi[n] * a0 / 4 / w / (1-w);
|
|
}
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10, yPos + 80 + psi[0]);
|
|
for (n = 0; n <= nn; n++)
|
|
{
|
|
ctx.lineTo(xPos + 10 + 160 * (n + 1) / nn, yPos + 80 + psi[n+1]);
|
|
}
|
|
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(3, -3);
|
|
}, 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> |