Files
WavesPrograms/11-4.html
2021-08-18 19:24:55 -07:00

168 lines
5.7 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 11-4
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
</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>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
var height = 70;
var dt = .2;
var omega = 1;
var nk = 1;
var k = nk * Math.PI / 80;
var eps = 5;
var mmax = 40;
var nx = 20;
var ny = 6;
var dxy = 80 / nx;
var dd = 2 * dxy * ny;
var stepX = 0.1;
var stepY = 0.1;
var clp = "#0000ff";
var otherColor = "#ff0000";
var cll = "#000000";
var xPos = -45;
var yPos = -30;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
ctx.scale(3, -3);
function fnpsix(x, y, t)
{
return -eps * Math.sin(k * x) * Math.cosh(k * y) * Math.cos(t);
}
function fnpsiy(x, y, t)
{
return eps * Math.cos(k * x) * Math.sinh(k * y) * Math.cos(t);
}
xp = new Array(nx + 1);
yp = new Array(nx + 1);
for (ix = 0; ix <= nx; ix++)
{
xp[ix] = new Array(ny + 1);
yp[ix] = new Array(ny + 1);
for (iy = 0; iy <= ny; iy++)
{
xp[ix][iy] = new Array(mmax + 1);
yp[ix][iy] = new Array(mmax + 1);
for (im = 0; im <= mmax; im++)
{
xp[ix][iy][im] = ix * dxy + fnpsix(ix * dxy, iy * dxy, 2 * Math.PI * im / mmax);
yp[ix][iy][im] = iy * dxy + fnpsiy(ix * dxy, iy * dxy, 2 * Math.PI * im / mmax);
}
}
}
function continuousXp(ix, iy, im)
{
return ix * dxy + fnpsix(ix * dxy, iy * dxy, 2 * Math.PI * im / mmax);
}
function continuousYp(ix, iy, im)
{
return iy * dxy + fnpsiy(ix * dxy, iy * dxy, 2 * Math.PI * im / mmax);
}
var m = 1;
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Draw();
m += 1;
if (m > mmax)
{
m = 1;
}
setTimeout(Update, 1000/60)
}
function Draw()
{
Clear(ctx);
ctx.strokeStyle = cll;
ctx.beginPath();
ctx.moveTo(xPos - 1, yPos - 1);
ctx.lineTo(xPos + 81, yPos - 1);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos - 1, yPos - 1);
ctx.lineTo(xPos - 1, yPos + dd + 1);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 81, yPos - 1);
ctx.lineTo(xPos + 81, yPos + dd + 1);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos - 1, yPos + dd + 1);
ctx.lineTo(xPos + 81, yPos + dd + 1);
ctx.stroke();
for (ix = 0; ix <= nx; ix += stepX)
{
for (iy = 0; iy <= ny; iy += stepY)
{
ctx.fillStyle = clp;
ctx.beginPath();
ctx.fillRect(xPos - 0.5 + continuousXp(ix, iy, m), yPos - 0.5 + continuousYp(ix, iy, m), 1, 1);
ctx.stroke();
}
}
for (ix = 0; ix <= nx; ix += stepX)
{
for (iy = 0; iy <= ny; iy += stepY)
{
ctx.fillStyle = otherColor;
ctx.beginPath();
ctx.fillRect(xPos + 80 - 0.5 - continuousXp(ix, iy, m), yPos - 0.5 + dd - continuousYp(ix, iy, m), 1, 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>