Files
WavesPrograms/6-1.html
2021-08-18 19:24:55 -07:00

135 lines
4.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 6-1
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
#increase
{
width: 50;
height: 50;
top: 12.5;
left: 12.5;
position: absolute;
background-image: url(upArrow.png);
background-repeat: no-repeat;
background-size: cover;
}
#decrease
{
width: 50;
height: 50;
top: 75;
left: 12.5;
position: absolute;
background-image: url(downArrow.png);
background-repeat: no-repeat;
background-size: cover;
}
</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>
<button id = "increase" onclick = "Increase()"></button>
<button id = "decrease" onclick = "Decrease()"></button>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
c.width = window.innerWidth;
c.height = window.innerHeight;
k = 1;
a0 = 40;
a = a0;
nn = 48;
mm0 = 24;
mm = mm0;
m = 1;
var xPos = -100;
var yPos = -75;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
ctx.scale(3, 3);
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Clear(ctx);
Draw();
m += 1;
ctx.strokeStyle = "#000000";
setTimeout(Update, 1000/60)
}
function Draw()
{
ctx.beginPath();
ctx.moveTo(xPos + 10, yPos + 80);
for (n = 0; n < nn; n++)
{
ctx.lineTo(xPos + 10 + 160 * (n + 1) / nn, yPos + 80 + a * Math.sin(k * (n+1) * Math.PI / nn) * Math.sin(m / mm));
}
ctx.stroke();
}
function Increase()
{
k += 1;
if (k > 10)
{
k = 10;
}
mm = mm0 / k;
a = a0 / k;
}
function Decrease()
{
k -= 1;
if (k <= 0)
{
k = 1;
}
mm = mm0 / k;
a = a0 / k;
}
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>