228 lines
8.0 KiB
HTML
228 lines
8.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 5-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: absolute;
|
|
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;"></canvas>
|
|
<div class="dropdown">
|
|
<button class="dropbtn" id="btn">1 Mass</button>
|
|
<div class="dropdown-content">
|
|
<button onclick="Blocks(2)">1 Mass</button>
|
|
<button onclick="Blocks(3)">2 Masses</button>
|
|
<button onclick="Blocks(4)">3 Masses</button>
|
|
<button onclick="Blocks(5)">4 Masses</button>
|
|
<button onclick="Blocks(6)">5 Masses</button>
|
|
<button onclick="Blocks(7)">6 Masses</button>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
var c = document.getElementById("myCanvas");
|
|
var ctx = c.getContext("2d");
|
|
var btn = document.getElementById("btn");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
var nn = 2;
|
|
var mm = new Array(nn);
|
|
var a = new Array (nn);
|
|
var mmax = 350;
|
|
nmax = nn;
|
|
var yy = new Array(nn + 1);
|
|
var xPos = -50;
|
|
var yPos = -50;
|
|
var m = 1;
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(4, -4);
|
|
|
|
for (k = 1; k <= nn - 1; k++)
|
|
{
|
|
mm[k] = 80 / Math.sqrt(3 - 2 * Math.cos(k * Math.PI / nn));
|
|
a[k] = 2 / nn;
|
|
}
|
|
|
|
var y = new Array(nn);
|
|
for (i = 0; i <= nn - 1; i++)
|
|
{
|
|
y[i] = new Array(nn);
|
|
for (j = 0; j <= nn; j++)
|
|
{
|
|
y[i][j] = new Array(Math.round(mm[1]));
|
|
for (k = 0; k <= mm[1]; k++)
|
|
{
|
|
y[i][j][k] = a[i]*4*Math.sin(i* Math.PI * j / nn) * Math.sin(2 * Math.PI * (k - 1) / mm[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function Blocks(num)
|
|
{
|
|
nn = num;
|
|
console.log(num);
|
|
btn.textContent = (num - 1) + " Masses";
|
|
|
|
nmax = nn;
|
|
for (k = 1; k <= nn - 1; k++)
|
|
{
|
|
mm[k] = 40 / Math.sqrt(3 - 2 * Math.cos(k * Math.PI / nn));
|
|
a[k] = 2 / nn;
|
|
}
|
|
|
|
y = new Array(nn);
|
|
for (i = 0; i <= nn - 1; i++)
|
|
{
|
|
y[i] = new Array(nn);
|
|
for (j = 0; j <= nn; j++)
|
|
{
|
|
y[i][j] = new Array(Math.round(mm[1]));
|
|
for (k = 0; k <= mm[1]; k++)
|
|
{
|
|
y[i][j][k] = a[i]*4*Math.sin(i* Math.PI * j / nn) * Math.sin(2 * Math.PI * (k - 1) / mm[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
Clear(ctx);
|
|
Draw();
|
|
m += 1;
|
|
setTimeout(Update, 1000/60)
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
|
|
for (n = 0; n < nn + 1; n++)
|
|
{
|
|
yy[n] = 0;
|
|
for (k = 1; k < nn; k++)
|
|
{
|
|
yy[n] += y[k][n][m % Math.round(mm[k])];
|
|
}
|
|
}
|
|
for (n = 1; n < nmax; n++)
|
|
{
|
|
ctx.strokeStyle = "#cccccc";
|
|
ctx.lineWidth = 0.5;
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80 * n / nmax, c.height);
|
|
ctx.lineTo(xPos + 10 + 80 * n / nmax, -c.height);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = "#000000";
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 10 + 80*n/nmax + yy[n], yPos + 82);
|
|
ctx.lineTo(xPos + 10 + 80*n/nmax, yPos + 100);
|
|
ctx.stroke();
|
|
ctx.strokeStyle = "#000000";
|
|
ctx.fillStyle = "#ffffff";
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 10 + 80 * n/nmax + yy[n], yPos + 80, 2, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 10 + 80 * n/nmax + yy[n], yPos + 80, 2, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
for (k = 1; k < nn; k++)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 10 + 80 * n/nmax + y[k][n][m % Math.round(mm[k])], yPos + k * 80/nn, 2, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.beginPath();
|
|
ctx.arc(xPos + 10 + 80 * n/nmax + y[k][n][m % Math.round(mm[k])], yPos + k * 80/nn, 2, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
for (n = 0; n < nmax; n++)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 12 + 80 * n / nmax + yy[n], yPos + 80);
|
|
ctx.lineTo(xPos + 8 + 80*(n+1)/nmax + yy[n+1], yPos + 80);
|
|
ctx.stroke();
|
|
for (k = 1; k < nn; k++)
|
|
{
|
|
ctx.beginPath();
|
|
ctx.moveTo(xPos + 12 + 80 * n/nmax + y[k][n][m % Math.round(mm[k])], yPos + k*80/nn);
|
|
ctx.lineTo(xPos + 8 + 80*(n+1)/nmax + y[k][n+1][m % Math.round(mm[k])], yPos + k*80/nn);
|
|
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> |