264 lines
10 KiB
HTML
264 lines
10 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: Water20
|
|
</title>
|
|
<style>
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0px;
|
|
border: 0;
|
|
overflow: hidden;
|
|
display: block;
|
|
}
|
|
|
|
canvas {
|
|
position: absolute;
|
|
}
|
|
|
|
form {
|
|
position: relative;
|
|
}
|
|
|
|
.slideContainer {
|
|
position: relative;
|
|
}
|
|
|
|
.slider {
|
|
width: 150px;
|
|
-webkit-appearance: none;
|
|
height: 8px;
|
|
border-radius: 4px;
|
|
background-color: rgb(0, 0, 255);
|
|
}
|
|
|
|
.slider::-webkit-slider-thumb {
|
|
-webkit-appearance: none;
|
|
width: 18px;
|
|
height: 18px;
|
|
border-radius: 10px;
|
|
background-color: rgb(200, 200, 200);
|
|
overflow: visible;
|
|
cursor: pointer;
|
|
}
|
|
</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>
|
|
<form>
|
|
<label for="toggle">Water particles</label>
|
|
<input type="checkbox" id="toggle" onclick="tClick()">
|
|
<br>
|
|
<label for="mtoggle">Swimmer</label>
|
|
<input type="checkbox" id="mtoggle" onclick="mtClick()">
|
|
<br>
|
|
<label for="ttoggle">Swimmer's path</label>
|
|
<input type="checkbox" id="ttoggle" onclick="ttClick()">
|
|
</form>
|
|
<div class="slidecontainer">
|
|
<t>Amplitude</t>
|
|
<input type="range" min="0" max="180" value="50" id="ampSlider" class = "slider">
|
|
</div>
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
ctx.canvas.width = window.innerWidth;
|
|
ctx.canvas.height = window.innerHeight;
|
|
|
|
var asp = 1;
|
|
var scrwidth = 1280;
|
|
console.log(scrwidth);
|
|
var ampSlider = document.getElementById("ampSlider");
|
|
var h = 70;
|
|
var nxb = 3;
|
|
var nyb = 3;
|
|
var modex = 1;
|
|
var modey = 1;
|
|
var ell = 100;
|
|
var c = .2;
|
|
var dt = .1;
|
|
var nn = 60;
|
|
var kw = 20;
|
|
var k = kw / 2.2 / scrwidth;
|
|
var depth = 120;
|
|
var htn = (Math.exp(k * depth) - Math.exp(-k * depth)) / (Math.exp(k * depth) + Math.exp(-k * depth));
|
|
var t = 0;
|
|
var m = 1;
|
|
var xPos = 0;
|
|
var yPos = -100;
|
|
var toggle = false;
|
|
var mtoggle = false;
|
|
var trace = false;
|
|
|
|
ampSlider.oninput = function()
|
|
{
|
|
h = this.value;
|
|
if (h > 143)
|
|
{
|
|
document.getElementById("ampSlider").style.backgroundColor = "#ff0000";
|
|
} else
|
|
{
|
|
document.getElementById("ampSlider").style.backgroundColor = "#0000ff";
|
|
}
|
|
}
|
|
|
|
function tClick()
|
|
{
|
|
checkBox = document.getElementById("toggle");
|
|
toggle = checkBox.checked;
|
|
Clear(ctx);
|
|
}
|
|
|
|
function mtClick()
|
|
{
|
|
checkBox = document.getElementById("mtoggle");
|
|
mtoggle = checkBox.checked;
|
|
Clear(ctx);
|
|
}
|
|
|
|
function ttClick()
|
|
{
|
|
checkBox = document.getElementById("ttoggle");
|
|
trace = checkBox.checked;
|
|
Clear(ctx);
|
|
}
|
|
|
|
function vector(xv, yv, xvv, yvv, va, cl)
|
|
{
|
|
vl = ((xvv - xv) ** 2 + Math.pow(yvv - yv, 2)) ** (1/2);
|
|
ctx.strokeStyle = cl;
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + xv, yPos + yv);
|
|
ctx.lineTo(xPos + xvv, yPos + yvv);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + xvv, yPos + yvv);
|
|
ctx.lineTo(xPos + xvv - va / vl * (xvv - xv) + va / vl / 2 * (yvv - yv), yPos + yvv - va / vl * (yvv - yv) - va / vl / 2 * (xvv - xv));
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + xvv, yPos + yvv);
|
|
ctx.lineTo(xPos + xvv - va / vl * (xvv - xv) - va / vl / 2 * (yvv - yv), yPos + yvv - va / vl * (yvv - yv) + va / vl / 2 * (xvv - xv));
|
|
ctx.stroke();
|
|
}
|
|
|
|
ctx.translate(scrwidth / 2, ctx.canvas.height / 2);
|
|
ctx.scale(1.5, -1.5);
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-scrwidth, -ctx.canvas.height, scrwidth * 2, ctx.canvas.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
Clear(ctx);
|
|
Draw();
|
|
m += 1;
|
|
setTimeout(Update, 1000/45);
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
ctx.strokeStyle = "#0000ff";
|
|
ctx.beginPath();
|
|
ctx.moveTo(-scrwidth, yPos);
|
|
ctx.lineTo(scrwidth, yPos);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.fillRect(-1.1 * scrwidth - h * Math.sin(-t) + xPos, htn * h * Math.cos(-t) + depth + yPos, 1, 1);
|
|
ctx.fill();
|
|
for (jj = -1; jj <= nn + 2; jj++)
|
|
{
|
|
x = 1.1 * scrwidth * (-1 + 2 * jj / nn);
|
|
xx = jj / nn * kw;
|
|
ctx.strokeStyle = "#0000ff";
|
|
ctx.lineTo(xPos + x - h * Math.sin(xx - t), yPos + htn * h * Math.cos(xx - t) + depth);
|
|
}
|
|
ctx.stroke();
|
|
|
|
hh = (h / Math.cosh(depth * k));
|
|
for (y = -50; y <= depth - 50; y += 20)
|
|
{
|
|
cky = Math.cosh(k * (y + 50));
|
|
sky = Math.sinh(k * (y + 50));
|
|
for (x = -1.1 * scrwidth; x <= 3.1 * scrwidth; x += 20)
|
|
{
|
|
if (toggle)
|
|
{
|
|
ctx.fillStyle = "#000000";
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + x - hh * Math.sin(k * x - t) * cky - 1.1 * scrwidth, yPos + y + 50 + hh * Math.cos(k * x - t) * sky, 1.5, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
}
|
|
xx = kw / 2;
|
|
if (mtoggle)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.arc(xPos -h * Math.sin(xx - t), yPos + htn * h * Math.cos(xx - t) + 3 + depth, 3, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
ctx.scale(1, 1.3);
|
|
ctx.beginPath();
|
|
ctx.arc(xPos -h * Math.sin(xx - t), yPos / 1.3 + 1/(1.3) * htn * h * Math.cos(xx - t) - 32 + depth, 3, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
ctx.scale(1, 1/(1.3));
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos - h * Math.sin(xx - t) - 3, yPos + htn * h * Math.cos(xx - t) - 2 + depth);
|
|
ctx.lineTo(xPos - h * Math.sin(xx - t) - 7, yPos + htn * h * Math.cos(xx - t) + 2 + depth);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos - h * Math.sin(xx - t) + 3, yPos + htn * h * Math.cos(xx - t) - 2 + depth);
|
|
ctx.lineTo(xPos - h * Math.sin(xx - t) + 7, yPos + htn * h * Math.cos(xx - t) + 2 + depth);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos - h * Math.sin(xx - t) + 2, yPos + htn * h * Math.cos(xx - t) - 11 + depth);
|
|
ctx.lineTo(xPos - h * Math.sin(xx - t) + 4, yPos + htn * h * Math.cos(xx - t) - 16 + depth);
|
|
ctx.stroke();
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos - h * Math.sin(xx - t) - 2, yPos + htn * h * Math.cos(xx - t) - 11 + depth);
|
|
ctx.lineTo(xPos - h * Math.sin(xx - t) - 4, yPos + htn * h * Math.cos(xx - t) - 16 + depth);
|
|
ctx.stroke();
|
|
}
|
|
ctx.strokeStyle = "#ff0000";
|
|
if (trace)
|
|
{
|
|
for (p = 0; p <= 101; p+= 0.1)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos -h * Math.sin(xx - p), yPos + htn * h * Math.cos(xx - p) - 4 + depth);
|
|
ctx.lineTo(xPos -h * Math.sin(xx - (p+ 0.1)), yPos + htn * h * Math.cos(xx - (p + 0.1)) - 4 + depth);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
t += dt;
|
|
ctx.strokeStyle = "#000000"
|
|
vector(0, 0, 30, 0, 10, 13);
|
|
vector(0, 0, 0, 30, 10, 13);
|
|
}
|
|
|
|
window.addEventListener('resize', function(event) {
|
|
ctx.canvas.width = window.innerWidth;
|
|
ctx.canvas.height = window.innerHeight;
|
|
ctx.translate(scrwidth / 2, ctx.canvas.height / 2);
|
|
ctx.scale(1.5, -1.5);
|
|
k = kw / 2.2 / scrwidth;
|
|
htn = (Math.exp(k * depth) - Math.exp(-k * depth)) / (Math.exp(k * depth) + Math.exp(-k * depth));
|
|
}, 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> |