Files
WavesPrograms/9-2.html
2021-08-18 19:24:55 -07:00

199 lines
7.6 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 9-2
</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");
c.width = window.innerWidth;
c.height = window.innerHeight;
var eps = new Array(3);
eps[0] = .85;
eps[1] = 2;
eps[2] = 5;
var mm = 40;
var mmax = 80;
var nn = 16;
var nn4 = nn/4;
var nmax = 2 * nn;
var xPos = -50;
var yPos = -50;
var m = 1;
var je = 1;
var th = Math.atan(eps[je] / 2);
var r = eps[je] / Math.sqrt(4 + Math.pow(eps[je], 2));
var t = 2 / Math.sqrt(4 + Math.pow(eps[je], 2));
var nth = (nn * th / 2 / Math.PI);
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
ctx.scale(3, -3);
var y1 = new Array(nn + 1);
var y2 = new Array(nn + 1);
for (n = 0; n < nn + 1; n++)
{
y1[n] = new Array(mm + 1);
y2[n] = new Array(mm + 1);
for (m = 0; m < mm + 1; m++)
{
y1[n][m] = 10 * Math.cos(2 * Math.PI * (n / nn - m / mm));
y2[n][m] = 10 * r * Math.cos(2 * Math.PI * (n / nn + m / mm));
}
}
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Clear(ctx);
Draw();
m += 1;
console.log(m);
setTimeout(Update, 1000/45)
}
function Draw()
{
ctx.strokeStyle = "#cccccc";
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 / nmax, 15 + yPos);
ctx.lineTo(xPos + 90 + 80 / nmax, 15 + yPos);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 / nmax, 40 + yPos);
ctx.lineTo(xPos + 90 + 80 / nmax, 40 + yPos);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 / nmax, 75 + yPos);
ctx.lineTo(xPos + 90 + 80 / nmax, 75 + yPos);
ctx.stroke();
ctx.strokeStyle = "#000000";
ctx.lineWidth = 1;
for (n = 1; n < nn; n++)
{
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + y1[n % nn][m % mm] + 15);
ctx.lineTo(xPos + 10 + 80 * (n+1) / nmax, yPos + y1[(n+1) % nn][m % mm] + 15);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + y2[(nn + n - nth - nn4) % nn][m % mm] + 40);
ctx.lineTo(xPos + 10 + 80 * (n+1) / nmax, yPos + y2[(nn + n - nth - nn4 +1) % nn][m % mm] + 40);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + y1[n % nn][m % mm] + y2[(nn + n - nth - nn4) % nn][m % mm] + 75);
ctx.lineTo(xPos + 10 + 80 * (n+1) / nmax, yPos + y1[(n+1) % nn][m % mm] + y2[(nn + n - nth - nn4 + 1) % nn][m % mm] + 75);
ctx.stroke();
}
for (n = nn; n <= nmax; n++)
{
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + t * y1[(n + nth) % nn][m % mm] + 15);
ctx.lineTo(xPos + 10 + 80 * (n + 1) / nmax, yPos + t * y1[(n + nth + 1) % nn][m % mm] + 15);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + t * y1[(n + nth) % nn][m % mm] + 75);
ctx.lineTo(xPos + 10 + 80 * (n + 1) / nmax, yPos + t * y1[(n + nth + 1) % nn][m % mm] + 75);
ctx.stroke();
}
var n = nn;
ctx.beginPath();
ctx.arc(xPos + 10 + 80 * n / nmax, yPos + t * y1[(n + nth) % nn][m % mm] + 75, 1, 0, Math.PI * 2);
ctx.fill();
var i;
}
function Case1()
{
je = 0;
var th = Math.atan(eps[je] / 2);
var r = eps[je] / Math.sqrt(4 + Math.pow(eps[je], 2));
var t = 2 / Math.sqrt(4 + Math.pow(eps[je], 2));
var nth = (nn * th / 2 / Math.PI);
for (n = 0; n < nn + 1; n++)
{
for (m = 0; m < mm + 1; m++)
{
y1[n][m] = 10 * Math.cos(2 * Math.PI * (n / nn - m / mm));
y2[n][m] = 10 * r * Math.cos(2 * Math.PI * (n / nn + m / mm));
}
}
}
function Case2()
{
je = 1;
var th = Math.atan(eps[je] / 2);
var r = eps[je] / Math.sqrt(4 + Math.pow(eps[je], 2));
var t = 2 / Math.sqrt(4 + Math.pow(eps[je], 2));
var nth = (nn * th / 2 / Math.PI);
for (n = 0; n < nn + 1; n++)
{
for (m = 0; m < mm + 1; m++)
{
y1[n][m] = 10 * Math.cos(2 * Math.PI * (n / nn - m / mm));
y2[n][m] = 10 * r * Math.cos(2 * Math.PI * (n / nn + m / mm));
}
}
}
function Case3()
{
je = 2;
var th = Math.atan(eps[je] / 2);
var r = eps[je] / Math.sqrt(4 + Math.pow(eps[je], 2));
var t = 2 / Math.sqrt(4 + Math.pow(eps[je], 2));
var nth = (nn * th / 2 / Math.PI);
for (n = 0; n < nn + 1; n++)
{
for (m = 0; m < mm + 1; m++)
{
y1[n][m] = 10 * Math.cos(2 * Math.PI * (n / nn - m / mm));
y2[n][m] = 10 * r * Math.cos(2 * Math.PI * (n / nn + m / mm));
}
}
}
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>