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

157 lines
5.9 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-1
</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="x">X mode</label>
<input type="number" id="x" name="x" min="1" max="10" step = "1" value = "1">
<br>
<label for="y">Y mode</label>
<input type="number" id="y" name="y" min="1" max="10" step = "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 cll = "#ff0000";
var dz = 10;
var nxb = 25;
var nyb = 25;
var modex = parseFloat(document.getElementById("x").value);
var modey = parseFloat(document.getElementById("y").value);
var ell = 10;
var ellx = ell * nxb;
var elly = ell * nyb;
var cTwo = .2;
var omega = 1;
var dt = .1;
var t = 0;
var m = 1;
var xPos = 0;
var yPos = 0;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
ctx.scale(1.5, -1.5);
function fnx(x, y, z)
{
return (x + y) / Math.SQRT2;
}
function fny(x, y, z)
{
return z + cTwo * (y - x);
}
function threedline(x1, y1, z1, x2, y2, z2, cll)
{
ctx.strokeStyle = cll;
ctx.beginPath();
ctx.moveTo(xPos + fnx(x1, y1, z1), yPos + fny(x1, y1, z1));
ctx.lineTo(xPos + fnx(x2, y2, z2), yPos + fny(x2, y2, z2));
ctx.stroke();
}
function fna(nx, ny)
{
return Math.sin(modex * Math.PI * nx / (nxb + 1)) * Math.sin(modey * Math.PI * ny / (nyb + 1));
}
function Clear(ctx)
{
console.log("Clear!");
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
document.getElementById("x").value = Math.round(document.getElementById("x").value);
document.getElementById("y").value = Math.round(document.getElementById("y").value);
modex = document.getElementById("x").value;
modey = document.getElementById("y").value;
if (modex <= 0)
{
modex = 1;
document.getElementById("x").value = 1;
} else if (modex > 5)
{
modex = 5;
document.getElementById("x").value = 5;
}
if (modey <= 0)
{
modey = 1;
document.getElementById("y").value = 1;
} else if (modey > 5)
{
modey = 5;
document.getElementById("y").value = 5;
}
omega = Math.sqrt((Math.pow(modex, 2) + Math.pow(modey, 2)) / 2);
Clear(ctx);
Draw();
m += 1;
console.log(m);
setTimeout(Update, 1000/60)
}
function Draw()
{
threedline(-ellx, -elly, 0, ellx, -elly, 0, cll);
threedline(-ellx, -elly, 0, -ellx, elly, 0, cll);
threedline(ellx, elly, 0, ellx, -elly, 0, cll);
threedline(ellx, elly, 0, -ellx, elly, 0, cll);
for (nx = 0; nx <= nxb; nx++)
{
for (ny = 0; ny <= nyb; ny++)
{
threedline(-ellx + 2 * ellx * nx / (nxb + 1), -elly + 2 * elly * ny / (nyb + 1), dz * Math.sin(omega * t) * fna(nx, ny), -ellx + 2 * ellx * (nx + 1) / (nxb + 1), -elly + 2 * elly * ny / (nyb + 1), dz * Math.sin(omega * t) * fna((nx + 1), (ny)), cll);
threedline(-ellx + 2 * ellx * nx / (nxb + 1), -elly + 2 * elly * ny / (nyb + 1), dz * Math.sin(omega * t) * fna(nx, ny), -ellx + 2 * ellx * (nx) / (nxb + 1), -elly + 2 * elly * (ny + 1) / (nyb + 1), dz * Math.sin(omega * t) * fna((nx), (ny + 1)), cll);
}
}
t += dt;
}
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);
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>