Added the rest of the files
This commit is contained in:
168
circularPendulum.html
Normal file
168
circularPendulum.html
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
Circular Pendulum
|
||||||
|
</title>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0px;
|
||||||
|
border: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.greenSlider {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
height: 10px;
|
||||||
|
background: #d3d3d3;
|
||||||
|
outline: none;
|
||||||
|
opacity: 0.7;
|
||||||
|
-webkit-transition: .2s;
|
||||||
|
transition: opacity .2s;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.greenSlider::-webkit-slider-thumb {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
background: #66ff77;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.greenSlider::-moz-range-thumb {
|
||||||
|
background: #66ff77;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
</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>
|
||||||
|
<div class="slidecontainer">
|
||||||
|
<t>Theta</t>
|
||||||
|
<input type="range" min="0.01" max="1.57" value="0.52" step="0.01" class="greenSlider" id="wRSlider">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var c = document.getElementById("myCanvas");
|
||||||
|
var ctx = c.getContext("2d");
|
||||||
|
c.width = window.innerWidth;
|
||||||
|
c.height = window.innerHeight;
|
||||||
|
//Time step
|
||||||
|
var dt = 0.01;
|
||||||
|
var t = 0;
|
||||||
|
var l = 100;
|
||||||
|
var theta = 0.52;
|
||||||
|
var w = Math.sqrt(980 / (l * Math.cos(theta)));
|
||||||
|
var cTwo = 0.2;
|
||||||
|
//Relative position of canvas
|
||||||
|
var xPos = 0;
|
||||||
|
var yPos = 70;
|
||||||
|
//Moves and scales canvas
|
||||||
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||||
|
ctx.scale(2, -2);
|
||||||
|
|
||||||
|
function fnx(x, y, z)
|
||||||
|
{
|
||||||
|
return (x + y) / Math.SQRT2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fny(x, y, z)
|
||||||
|
{
|
||||||
|
return z + cTwo * (y - x);
|
||||||
|
}
|
||||||
|
|
||||||
|
wRSlider.oninput = function()
|
||||||
|
{
|
||||||
|
theta = this.value;
|
||||||
|
w = Math.sqrt(980 / (l * Math.cos(theta)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function Clear(ctx)
|
||||||
|
{
|
||||||
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Update()
|
||||||
|
{
|
||||||
|
Clear(ctx);
|
||||||
|
Draw();
|
||||||
|
t += dt;
|
||||||
|
setTimeout(Update, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Reset()
|
||||||
|
{
|
||||||
|
t = 0;
|
||||||
|
rp = 0;
|
||||||
|
thetap = 0;
|
||||||
|
theta = Math.PI / 18;
|
||||||
|
r = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Draw()
|
||||||
|
{
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(xPos + fnx(0, 0, 0), yPos + fny(0, 0, 0));
|
||||||
|
ctx.lineTo(
|
||||||
|
xPos + fnx(l * Math.sin(theta) * Math.cos(t * w), - l * Math.sin(theta) * Math.sin(t * w), - l * Math.cos(theta)),
|
||||||
|
yPos + fny(l * Math.sin(theta) * Math.cos(t * w), - l * Math.sin(theta) * Math.sin(t * w), - l * Math.cos(theta))
|
||||||
|
);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(
|
||||||
|
xPos + fnx(l * Math.sin(theta) * Math.cos(t * w), - l * Math.sin(theta) * Math.sin(t * w), - l * Math.cos(theta)),
|
||||||
|
yPos + fny(l * Math.sin(theta) * Math.cos(t * w), - l * Math.sin(theta) * Math.sin(t * w), - l * Math.cos(theta)),
|
||||||
|
5, 0, Math.PI * 2
|
||||||
|
);
|
||||||
|
ctx.fill();
|
||||||
|
iStep = Math.PI / 100;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(
|
||||||
|
xPos + fnx(l * Math.sin(theta) * Math.cos(0), - l * Math.sin(theta) * Math.sin(0), - l * Math.cos(theta)),
|
||||||
|
yPos + fny(l * Math.sin(theta) * Math.cos(0), - l * Math.sin(theta) * Math.sin(0), - l * Math.cos(theta))
|
||||||
|
);
|
||||||
|
for (i = 0; i <= Math.PI * 2; i += iStep)
|
||||||
|
{
|
||||||
|
ctx.lineTo(
|
||||||
|
xPos + fnx(l * Math.sin(theta) * Math.cos(i), - l * Math.sin(theta) * Math.sin(i), - l * Math.cos(theta)),
|
||||||
|
yPos + fny(l * Math.sin(theta) * Math.cos(i), - l * Math.sin(theta) * Math.sin(i), - l * Math.cos(theta))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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(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>
|
||||||
151
exercise1-7.html
Normal file
151
exercise1-7.html
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<!--
|
||||||
|
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>
|
||||||
|
Exercise 1-7
|
||||||
|
</title>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0px;
|
||||||
|
border: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
t {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 75px;
|
||||||
|
left: 5%;
|
||||||
|
top: 5%;
|
||||||
|
}
|
||||||
|
</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>
|
||||||
|
<t id="time">0</t>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var c = document.getElementById("myCanvas");
|
||||||
|
var ctx = c.getContext("2d");
|
||||||
|
c.width = window.innerWidth;
|
||||||
|
c.height = window.innerHeight;
|
||||||
|
//Time step
|
||||||
|
var dt = 0.01;
|
||||||
|
var t = 0;
|
||||||
|
var g = 980;
|
||||||
|
var lx = 200;
|
||||||
|
var ly = 200;
|
||||||
|
var pulleyR = 2;
|
||||||
|
var r = 100;
|
||||||
|
var rp = 0;
|
||||||
|
var theta = Math.PI / 18;
|
||||||
|
var thetap = 0;
|
||||||
|
//Relative position of canvas
|
||||||
|
var xPos = 0;
|
||||||
|
var yPos = 70;
|
||||||
|
//Moves and scales canvas
|
||||||
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||||
|
ctx.scale(2, -2);
|
||||||
|
|
||||||
|
function Clear(ctx)
|
||||||
|
{
|
||||||
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Update()
|
||||||
|
{
|
||||||
|
Clear(ctx);
|
||||||
|
Draw();
|
||||||
|
t += dt;
|
||||||
|
|
||||||
|
if (t == 0)
|
||||||
|
{
|
||||||
|
console.log("zero");
|
||||||
|
rp = 0;
|
||||||
|
thetap = 0;
|
||||||
|
theta = Math.PI / 18;
|
||||||
|
r = 100;
|
||||||
|
}
|
||||||
|
if (t >= 0)
|
||||||
|
{
|
||||||
|
document.getElementById("time").textContent = t.toFixed(2) + " seconds";
|
||||||
|
console.log("greater");
|
||||||
|
rp += (dt / 2) * ((r * thetap * thetap) - g * (1 - Math.cos(theta)));
|
||||||
|
r += rp * dt;
|
||||||
|
thetap += dt * (-(2 * rp * thetap / r) - (g * Math.sin(theta) / r));
|
||||||
|
theta += thetap * dt;
|
||||||
|
}
|
||||||
|
if (r >= 200)
|
||||||
|
{
|
||||||
|
console.log(t);
|
||||||
|
t = -1000;
|
||||||
|
setTimeout(Reset, 2000);
|
||||||
|
r = 199.99;
|
||||||
|
}
|
||||||
|
setTimeout(Update, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Reset()
|
||||||
|
{
|
||||||
|
t = 0;
|
||||||
|
rp = 0;
|
||||||
|
thetap = 0;
|
||||||
|
theta = Math.PI / 18;
|
||||||
|
r = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Draw()
|
||||||
|
{
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(xPos + lx / 2, yPos + pulleyR);
|
||||||
|
ctx.lineTo(xPos - lx / 2, yPos + pulleyR);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(xPos + lx / 2, yPos, pulleyR, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(xPos - lx / 2, yPos, pulleyR, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(xPos + lx / 2 + pulleyR, yPos);
|
||||||
|
ctx.lineTo(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta));
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(xPos - lx / 2 - pulleyR, yPos);
|
||||||
|
ctx.lineTo(xPos - lx / 2 - pulleyR, yPos - (250 - r));
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta), 5, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(xPos - lx / 2 - pulleyR, yPos - (250 - r), 5, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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>
|
||||||
Reference in New Issue
Block a user