204 lines
6.8 KiB
HTML
204 lines
6.8 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 8-6
|
|
</title>
|
|
<style>
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0px;
|
|
border: 0;
|
|
overflow: hidden;
|
|
display: block;
|
|
}
|
|
|
|
canvas {
|
|
position: absolute;
|
|
}
|
|
|
|
.container
|
|
{
|
|
position: relative;
|
|
}
|
|
#omegaIncrease
|
|
{
|
|
left: 12.5px;
|
|
top: 12.5px;
|
|
width: 100px;
|
|
height: 50px;
|
|
position: absolute;
|
|
}
|
|
#omegaDecrease
|
|
{
|
|
left: 12.5px;
|
|
top: 75px;
|
|
width: 100px;
|
|
height: 50px;
|
|
position: absolute;
|
|
}
|
|
#domegaIncrease
|
|
{
|
|
left: 12.5px;
|
|
top: 137.5px;
|
|
width: 100px;
|
|
height: 50px;
|
|
position: absolute;
|
|
}
|
|
#domegaDecrease
|
|
{
|
|
left: 12.5px;
|
|
top: 200px;
|
|
width: 100px;
|
|
height: 50px;
|
|
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>
|
|
<div class="container">
|
|
<button type="button" id="omegaIncrease" onclick="increase86()">Increase ω</button>
|
|
<button type="button" id="omegaDecrease" onclick="decrease86()">Decrease ω</button>
|
|
<button type="button" id="domegaIncrease" onclick="increasel86()">Increase Δω</button>
|
|
<button type="button" id="domegaDecrease" onclick="decreasel86()">Decrease Δω</button>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
var nn = 7;
|
|
var domega = .05;
|
|
var omega = 6;
|
|
var dt = .03;
|
|
var t = 0;
|
|
var m = 1;
|
|
var yy = new Array(nn + 2);
|
|
var xPos = -50;
|
|
var yPos = -50;
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(3, -3);
|
|
|
|
function fny86(x, t)
|
|
{
|
|
if (omega < 7 && omega > 5)
|
|
{
|
|
k = 2 * Math.atan(Math.sqrt(Math.pow(omega, 2) - 25) / (49 - Math.pow(omega, 2)));
|
|
return 10 * Math.cos(k * x - omega * t);
|
|
} else if (omega > 7)
|
|
{
|
|
k = 2 * Math.log10(Math.sqrt((Math.pow(omega, 2) - 49) / 14) + Math.sqrt((Math.pow(omega, 2) - 25) / 14));
|
|
return 10 * Math.exp(-k * x) * Math.cos(Math.PI * x) * Math.cos(omega * t);
|
|
} else if (omega < 5)
|
|
{
|
|
k = 2 * Math.log10(Math.sqrt((49 - Math.pow(omega, 2)) / 14) + Math.sqrt((25 - Math.pow(omega, 2)) / 14));
|
|
return 10 * Math.exp(-k * x) * Math.cos(omega * t);
|
|
} else if (omega == 7)
|
|
{
|
|
return 10 * Math.cos(Math.PI * x) * Math.cos(omega * t);
|
|
} else if (omega == 5)
|
|
{
|
|
return 10 * Math.cos(omega * t);
|
|
}
|
|
}
|
|
|
|
function increase86()
|
|
{
|
|
omega += domega;
|
|
}
|
|
|
|
function decrease86()
|
|
{
|
|
omega -= domega;
|
|
}
|
|
|
|
function increasel86()
|
|
{
|
|
if (domega < .02)
|
|
{
|
|
domega *= 10;
|
|
}
|
|
}
|
|
|
|
function decreasel86()
|
|
{
|
|
if (domega > .000002)
|
|
{
|
|
domega /= 10;
|
|
}
|
|
}
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
Clear(ctx);
|
|
Draw();
|
|
m += 1;
|
|
t += dt;
|
|
console.log(m);
|
|
setTimeout(Update, 1000/60)
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10, yPos + 50);
|
|
ctx.lineTo(xPos + 100 + 80 / nn, yPos + 50);
|
|
ctx.stroke();
|
|
for (n = 0; n < nn + 2; n++)
|
|
{
|
|
yy[n] = fny86(n, t);
|
|
}
|
|
for (n = 0; n < nn + 1; n++)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80 * n / nn, yPos + yy[n] + 50);
|
|
ctx.lineTo(xPos + 10 + 80 * (n + 1) / nn, yPos + yy[n+1] + 50);
|
|
ctx.stroke();
|
|
}
|
|
for (n = 1; n < nn + 2; n++)
|
|
{
|
|
ctx.fillStyle = "#000000";
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 10 + 80 * n / nn, yPos + yy[n] + 50, 2, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80 * n / nn, yPos + 50);
|
|
ctx.lineTo(xPos + 10.5 + 80 * n / nn, yPos + yy[n] / 2 + 50);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80 * n / nn, yPos + yy[n] + 50);
|
|
ctx.lineTo(xPos + 10.5 + 80 * n / nn, yPos + yy[n] / 2 + 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(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>
|