Files
WavesPrograms/12-1.html
2021-08-19 17:45:00 -07:00

233 lines
7.1 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 12-1
</title>
<style>
.container
{
position: relative;
}
#u1IncreaseButton
{
left: 12.5px;
top: 12.5px;
width: 100px;
height: 50px;
position: absolute;
}
#u1DecreaseButton
{
left: 12.5px;
top: 75px;
width: 100px;
height: 50px;
position: absolute;
}
#u2IncreaseButton
{
left: 12.5px;
top: 137.5px;
width: 100px;
height: 50px;
position: absolute;
}
#u2DecreaseButton
{
left: 12.5px;
top: 200px;
width: 100px;
height: 50px;
position: absolute;
}
#phiIncreaseButton
{
left: 12.5px;
top: 262.5px;
width: 100px;
height: 50px;
position: absolute;
}
#phiDecreaseButton
{
left: 12.5px;
top: 325px;
width: 100px;
height: 50px;
position: absolute;
}
canvas
{
position: absolute;
}
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;"></canvas>
<div class="container">
<button type="button" id="u1IncreaseButton" onclick="u1Increase()">Increase u1</button>
<button type="button" id="u1DecreaseButton" onclick="u1Decrease()">Decrease u1</button>
<button type="button" id="u2IncreaseButton" onclick="u2Increase()">Increase |u2|</button>
<button type="button" id="u2DecreaseButton" onclick="u2Decrease()">Decrease |u2|</button>
<button type="button" id="phiIncreaseButton" onclick="phiIncrease()">Increase phi</button>
<button type="button" id="phiDecreaseButton" onclick="phiDecrease()">Decrease phi</button>
</div>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
var scrwidth = 200;
var u1 = 1;
var phi1 = 0;
var u2 = 1;
var phi2 = 0;
var dt = .03;
var t = 0;
var cl1 = "#ee0000";
var cl2 = "#66ff77";
var cl3 = "#9999ff";
var cl4 = "#000000";
var nmu = 10;
var nphi = 0;
var nmphi = 10;
var nu1 = nmu;
var nu2 = nmu;
var mmm = 24;
var xPos = -10;
var yPos = -10;
var m = 1;
var stepSize = 0.5;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
ctx.scale(1.5, -1.5);
function Update()
{
Draw();
m += 1;
setTimeout(Update, 1000/60);
}
Update();
function Draw()
{
Clear(ctx);
ctx.strokeStyle = cl1;
ctx.beginPath();
ctx.moveTo(xPos, yPos);
ctx.lineTo(xPos + 100 * u1 * Math.cos(t - phi1), yPos);
ctx.stroke();
ctx.strokeStyle = cl2;
ctx.beginPath();
ctx.moveTo(xPos, yPos);
ctx.lineTo(xPos, yPos + 100 * u2 * Math.cos(t - phi2));
ctx.stroke();
ctx.strokeStyle = cl3;
ctx.beginPath();
ctx.moveTo(xPos, yPos);
ctx.lineTo(xPos + 100 * u1 * Math.cos(t - phi1), yPos + 100 * u2 * Math.cos(t - phi2));
ctx.stroke();
ctx.strokeStyle = "#000000";
for (mm = 0; mm <= mmm; mm += stepSize)
{
ctx.fillStyle = cl4;
ctx.beginPath();
ctx.arc(xPos + 100 * u1 * Math.cos(2 * Math.PI * mm / mmm - phi1), yPos + 100 * u2 * Math.cos(2 * Math.PI * mm / mmm - phi2), 1, 0, Math.PI * 2);
ctx.stroke();
}
t += dt;
}
function u1Increase()
{
if (nu1 < nmu)
{
nu1 += 1;
}
u1 = nu1 / nmu;
}
function u1Decrease()
{
if (nu1 > 0)
{
nu1 -= 1;
}
u1 = nu1 / nmu;
}
function u2Increase()
{
if (nu2 < nmu)
{
nu2 += 1;
}
u2 = nu2 / nmu;
}
function u2Decrease()
{
if (nu2 > 0)
{
nu2 -= 1;
}
u2 = nu2 / nmu;
}
function phiDecrease()
{
nphi = nphi - 1;
if (nphi <= -nmphi)
{
nphi += 2 * nmphi;
}
phi2 = nphi * Math.PI / nmphi;
}
function phiIncrease()
{
nphi = nphi + 1;
if (nphi > nmphi)
{
nphi -= 2 * nmphi;
}
phi2 = nphi * Math.PI / nmphi;
}
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);
</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>