198 lines
7.2 KiB
HTML
198 lines
7.2 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 7-1
|
|
</title>
|
|
<style>
|
|
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0px;
|
|
border: 0;
|
|
overflow: hidden;
|
|
display: block;
|
|
}
|
|
|
|
canvas {
|
|
position: absolute;
|
|
}
|
|
|
|
.dropbtn {
|
|
background-color: #04AA6D;
|
|
color: white;
|
|
padding: 16px;
|
|
font-size: 16px;
|
|
border: none;
|
|
}
|
|
|
|
.dropdown {
|
|
position: relative;
|
|
display: inline-block;
|
|
}
|
|
|
|
.dropdown-content {
|
|
display: none;
|
|
position: relative;
|
|
background-color: #f1f1f1;
|
|
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
|
|
z-index: 1;
|
|
}
|
|
|
|
.dropdown-content button {
|
|
color: black;
|
|
padding: 12px 16px;
|
|
width: 100px;
|
|
text-decoration: none;
|
|
display: block;
|
|
}
|
|
|
|
.dropdown-content a:hover {background-color: #ddd;}
|
|
|
|
.dropdown:hover .dropdown-content {display: block;}
|
|
|
|
.dropdown:hover .dropbtn {background-color: #3e8e41;}
|
|
</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="dropdown">
|
|
<button class="dropbtn" id="btn">kL = 1 * π</button>
|
|
<div class="dropdown-content">
|
|
<button onclick="Nodes(1)">kL = 1 * π</button>
|
|
<button onclick="Nodes(2)">kL = 2 * π</button>
|
|
<button onclick="Nodes(3)">kL = 3 * π</button>
|
|
<button onclick="Nodes(4)">kL = 4 * π</button>
|
|
<button onclick="Nodes(5)">kL = 5 * π</button>
|
|
<button onclick="Nodes(6)">kL = 6 * π</button>
|
|
<button onclick="Nodes(7)">kL = 7 * π</button>
|
|
<button onclick="Nodes(8)">kL = 8 * π</button>
|
|
<button onclick="Nodes(9)">kL = 9 * π</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
var nodes = 1;
|
|
var nn = 42;
|
|
var eps = 20 / nodes;
|
|
var kl = Math.PI * nodes;
|
|
var o = 2 * nodes;
|
|
var xPos = -90;
|
|
var yPos = -50;
|
|
var m = 1;
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(6, -6);
|
|
|
|
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/60)
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
drawOscillatingSpring(1, 7, 160, 10, 50, xPos, 0, 0.1)
|
|
}
|
|
|
|
function drawOscillatingSpring(a, b, xSize, ySize, numLoops, x, y, tStep)
|
|
{
|
|
//Draws coiled spring using prolate cycloid
|
|
var tStart = Math.PI / 2;
|
|
var tEnd = (3 * Math.PI / 2) + (2 * Math.PI * numLoops);
|
|
var xEnd = a * tEnd - b * Math.sin(tEnd);
|
|
var yEnd = a + b;
|
|
var xFactor = xSize / xEnd;
|
|
var yFactor = ySize / yEnd;
|
|
var xShiftA = - a * (Math.PI / 2) + b * Math.sin(Math.PI / 2);
|
|
var yShift = y - a + b * Math.cos(Math.PI / 2);
|
|
ctx.beginPath();
|
|
var xDisplacement = eps * Math.sin(m * 0.1) * Math.sin((xFactor * (a * Math.PI / 2 - b * Math.sin(Math.PI / 2)) + xShiftA) * nodes * Math.PI / xSize);
|
|
ctx.moveTo(xShiftA + x + xDisplacement + xFactor * (a * Math.PI / 2 - b * Math.sin(Math.PI / 2)), yShift + yFactor * (a - b * Math.cos(Math.PI / 2)));
|
|
for (t = tStart; t <= tEnd; t += tStep)
|
|
{
|
|
xDisplacement = eps * Math.sin(m * 0.1) * Math.sin((xFactor * (a * t - b * Math.sin(t)) + xShiftA) * nodes * Math.PI / xSize);
|
|
//ctx.moveTo(xShiftA + x + xDisplacement + xFactor * (a * t - b * Math.sin(t)), yShift + yFactor * (a - b * Math.cos(t)));
|
|
ctx.lineTo(xShiftA + x + xDisplacement + xFactor * (a * (t + tStep) - b * Math.sin(t + tStep)), yShift + yFactor * (a - b * Math.cos(t + tStep)));
|
|
}
|
|
ctx.stroke();
|
|
}
|
|
|
|
function Nodes(num)
|
|
{
|
|
nodes = num;
|
|
btn.textContent = "kL = " + nodes.toString();
|
|
eps = 20 / nodes;
|
|
kl = Math.PI * nodes;
|
|
o = 2 * nodes;
|
|
}
|
|
|
|
document.onkeypress = function (e) {
|
|
e = e || window.event;
|
|
if (e.keyCode == 49)
|
|
{
|
|
nodes = 1;
|
|
} else if (e.keyCode == 50)
|
|
{
|
|
nodes = 2;
|
|
} else if (e.keyCode == 51)
|
|
{
|
|
nodes = 3;
|
|
} else if (e.keyCode == 52)
|
|
{
|
|
nodes = 4;
|
|
} else if (e.keyCode == 53)
|
|
{
|
|
nodes = 5;
|
|
} else if (e.keyCode == 54)
|
|
{
|
|
nodes = 6;
|
|
} else if (e.keyCode == 55)
|
|
{
|
|
nodes = 7;
|
|
} else if (e.keyCode == 56)
|
|
{
|
|
nodes = 8;
|
|
} else if (e.keyCode == 57)
|
|
{
|
|
nodes = 9;
|
|
}
|
|
btn.textContent = "kl = " + nodes.toString();
|
|
eps = 20 / nodes;
|
|
kl = Math.PI * nodes;
|
|
o = 2 * nodes;
|
|
};
|
|
|
|
|
|
window.addEventListener('resize', function(event) {
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
ctx.translate(c.width / 2, c.height / 2);
|
|
ctx.scale(6, -6);
|
|
}, 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> |