Files
WavesPrograms/12-2.html
2021-08-18 19:24:55 -07:00

149 lines
4.7 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-2
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
</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>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
var screenasp = 1;
var plotarea = 200;
var k12 = 3;
var nn = 2;
var dt = .1 * nn;
var o1 = new Array(nn + 1);
var o2 = new Array(nn + 1);
var f1 = new Array(nn + 1);
var f2 = new Array(nn + 1);
var d = 30;
var colorSpeed = 1;
var maxReps = 1;
var xPos = -100;
var yPos = -100;
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
ctx.scale(2, -2);
for (j = 1; j <= nn; j++)
{
o1[j] = Math.random() - 0.5;
o2[j] = Math.random() - 0.5;
f1[j] = (Math.random() - 0.5) * Math.PI;
f2[j] = (Math.random() - 0.5) * Math.PI;
}
function x(t)
{
fx = 0;
for (j = 1; j <= nn; j++)
{
fx += Math.cos((1 + o1[j] / d) * t + f1[j]);
}
return fx / nn;
}
function y(t)
{
fy = 0;
for (j = 1; j <= nn; j++)
{
fy += Math.cos((1 + o2[j] / d) * t + f1[j]);
}
return fy / nn;
}
var xmin = -1;
var xmax = 1;
var ymin = -1;
var ymax = 1;
function xx(x)
{
return 200 * (x - xmin) / (xmax - xmin);
}
function yy(y)
{
return 200 * (y - ymin) / (ymax - ymin);
}
function Fade()
{
for (i = 0; i <= maxReps; i++)
{
ctx.globalAlpha = 0.025;
ctx.fillStyle = "#ffffff";
ctx.beginPath();
ctx.fillRect(-c.width, -c.height, c.width * 2, c.height * 2);
ctx.stroke();
ctx.globalAlpha = 1;
}
setTimeout(Fade, 2000)
}
var x1 = x(0);
var y1 = y(0);
var t = 0;
Fade(ctx);
function Update()
{
t += dt;
nx = x(t);
ny = y(t);
xFactor = 1;
yFactor = 1;
//xFactor = c.width / 400;
//yFactor = c.height / 400;
ctx.strokeStyle = "hsl(" + (t * colorSpeed) % 360 + ",100%,50%)";
ctx.beginPath();
ctx.moveTo((xx(x1) + xPos) * xFactor, (yy(y1) + yPos) * yFactor);
ctx.lineTo((xx(nx) + xPos) * xFactor, (yy(ny) + yPos) * yFactor);
ctx.stroke();
x1 = nx;
y1 = ny;
setTimeout(Update, 500/60)
}
window.addEventListener('resize', function(event) {
c.width = window.innerWidth;
c.height = window.innerHeight;
ctx.translate(c.width / 2, c.height / 2);
ctx.scale(2, -2);
}, 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>