Added the rest of the files
This commit is contained in:
145
3-1.html
Normal file
145
3-1.html
Normal file
@@ -0,0 +1,145 @@
|
||||
<!--
|
||||
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 3-1
|
||||
</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 bottom = -50;
|
||||
//var side = 300;
|
||||
//var t = 1;
|
||||
//var ii = 800 * t;
|
||||
var tm = .1;
|
||||
var om = .1;
|
||||
var dom = .02;
|
||||
var a1 = 1;
|
||||
var a2 = 0;
|
||||
var b1 = 0;
|
||||
var b2 = .4;
|
||||
//var asp = 1;
|
||||
var i = 1;
|
||||
var y1 = 0;
|
||||
var y2 = 0;
|
||||
var x1 = 0;
|
||||
var x2 = 0;
|
||||
var xPos = 0;
|
||||
var yPos = -100;
|
||||
|
||||
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
|
||||
ctx.scale(1.5, 1.5);
|
||||
|
||||
|
||||
function Clear(ctx)
|
||||
{
|
||||
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||
}
|
||||
|
||||
function Update()
|
||||
{
|
||||
var theta11 = tm * (a1 * Math.cos(om*i) + b1 * Math.sin(om*i));
|
||||
var theta21 = tm * (a1 * Math.cos(om*i) + b1 * Math.sin(om*i));
|
||||
var theta12 = tm * (a2 * Math.cos((om + dom)*i) + b2 * Math.sin((om + dom)*i));
|
||||
var theta22 = tm * (-a2 * Math.cos((om + dom)*i) - b2 * Math.sin((om + dom)*i));
|
||||
var theta1 = theta11 + theta12;
|
||||
var theta2 = theta21 + theta22;
|
||||
theta2 = tm * (a1 * Math.cos(om*i) - a2 * Math.cos((om+dom)*i) + b1* Math.sin(om*i) - b2*Math.sin((om+dom)*i));
|
||||
y1 = yPos + 200 * Math.cos(theta1);
|
||||
y2 = yPos + 200 * Math.cos(theta2);
|
||||
x1 = (xPos - 50) - 200 * Math.sin(theta1);
|
||||
x2 = (xPos + 50) - 200 * Math.sin(theta2);
|
||||
Draw();
|
||||
i += 1;
|
||||
setTimeout(Update, 1000/60)
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
Clear(ctx);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x1, y1);
|
||||
ctx.lineTo(xPos - 50, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x2, y2);
|
||||
ctx.lineTo(xPos + 50, yPos);
|
||||
ctx.stroke();
|
||||
drawSpring(1, 3, x2 - x1, 5, 7, x1, y1, 0.1, y2 - y1);
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.beginPath();
|
||||
ctx.arc(x1, y1, 7, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.beginPath();
|
||||
ctx.arc(x2, y2, 7, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.beginPath();
|
||||
ctx.arc(x1, y1, 7, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(x2, y2, 7, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function drawSpring(a, b, xSize, ySize, numLoops, x, y, tStep, deltaY)
|
||||
{
|
||||
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 xShift = x - a * (Math.PI / 2) + b * Math.sin(Math.PI / 2);
|
||||
var yShift = y - a + b * Math.cos(Math.PI / 2);
|
||||
var slope = deltaY / xSize;
|
||||
for (p = tStart; p <= tEnd; p += tStep)
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xShift + xFactor * (a * p - b * Math.sin(p)), yShift + yFactor * (a - b * Math.cos(p)) + slope * (a * p - b * Math.sin(p)));
|
||||
ctx.lineTo(xShift + xFactor * (a * (p + tStep) - b * Math.sin(p + tStep)), yShift + yFactor * (a - b * Math.cos(p + tStep)));
|
||||
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(1.5, 1.5);
|
||||
}, 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>
|
||||
Reference in New Issue
Block a user