122 lines
4.0 KiB
HTML
122 lines
4.0 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 10-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 v = 1;
|
|
var g = 1;
|
|
var x0 = -15;
|
|
var x1 = 15;
|
|
var t0 = -10;
|
|
var t1 = 30;
|
|
var mmax = 120;
|
|
var nmax = 90;
|
|
var a = 30;
|
|
var m = 1;
|
|
var xPos = -50;
|
|
var yPos = -50;
|
|
|
|
function thexp(x)
|
|
{
|
|
if (x < 0)
|
|
{
|
|
return 0;
|
|
} else
|
|
{
|
|
return Math.exp(-g * x);
|
|
}
|
|
}
|
|
|
|
function fng(x, t)
|
|
{
|
|
if (x < 0)
|
|
{
|
|
return Math.exp(-g * Math.abs(t - x/v)) - Math.exp( -g * Math.abs(t + x / v)) / 2 + g *(t + x/v) * thexp(t + x/v);
|
|
} else
|
|
{
|
|
return Math.exp(-g * Math.abs(t - x/v)) / 2 + g * (t - x/v) * thexp(t - x/v);
|
|
}
|
|
}
|
|
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(4, -4);
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
t = t0 + m * (t1 - t0) / mmax;
|
|
Draw();
|
|
m += 1;
|
|
if (m > mmax)
|
|
{
|
|
m = 1;
|
|
}
|
|
setTimeout(Update, 1000/45)
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
Clear(ctx);
|
|
for (n = 0; n <= nmax; n++)
|
|
{
|
|
x = x0 + n * (x1 - x0) / nmax;
|
|
xx = x + (x1 - x0) / nmax;
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80 * n / nmax, yPos + a * fng(x, t) + 50);
|
|
ctx.lineTo(xPos + 10 + 80 * (n + 1) / nmax, yPos + a * fng(xx, t) + 50);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 50, yPos + a * fng(0, t) + 50, 1, 0, Math.PI * 2);
|
|
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(4, -4);
|
|
}, 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> |