153 lines
5.2 KiB
HTML
153 lines
5.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>
|
|
Problem 7-4
|
|
</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: #000000;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.greenSlider::-moz-range-thumb {
|
|
background: #000000;
|
|
border-radius: 50%;
|
|
width: 15px;
|
|
height: 15px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<form>
|
|
<label for="k">k</label>
|
|
<input type="number" id="k" name="k" min="-2" max="10" step = "0.1" value = "2">
|
|
</form>
|
|
<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");
|
|
c.width = window.innerWidth;
|
|
c.height = window.innerHeight;
|
|
//Time step
|
|
var dt = 0.01;
|
|
var t = 0;
|
|
var omegaTheta = 1;
|
|
var r = 200;
|
|
var k = 2;
|
|
var omegaR = omegaTheta * Math.sqrt(k + 2);
|
|
var smallAmp = 20;
|
|
var xPositions = new Array();
|
|
var yPositions = new Array();
|
|
//Relative position of canvas
|
|
var xPos = 0;
|
|
var yPos = 0;
|
|
//Moves and scales canvas
|
|
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
|
ctx.scale(1, -1);
|
|
|
|
function changeK(newK)
|
|
{
|
|
k = newK;
|
|
omegaR = omegaTheta * Math.sqrt(k + 2);
|
|
Reset();
|
|
}
|
|
|
|
function Clear(ctx)
|
|
{
|
|
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
|
}
|
|
|
|
function Update()
|
|
{
|
|
if (parseFloat(document.getElementById("k").value) != k)
|
|
{
|
|
changeK(parseFloat(document.getElementById("k").value));
|
|
}
|
|
Clear(ctx);
|
|
Draw();
|
|
t += dt;
|
|
setTimeout(Update, 1);
|
|
}
|
|
|
|
function Reset()
|
|
{
|
|
t = 0;
|
|
xPositions = new Array();
|
|
yPositions = new Array();
|
|
}
|
|
|
|
function Draw()
|
|
{
|
|
ctx.setLineDash([5, 5]);
|
|
ctx.beginPath();
|
|
ctx.arc(xPos, yPos, r, 0, Math.PI * 2);
|
|
ctx.stroke();
|
|
xPositions.push((r + smallAmp * Math.cos(omegaR * t)) * Math.cos(omegaTheta * t));
|
|
yPositions.push((r + smallAmp * Math.cos(omegaR * t)) * Math.sin(omegaTheta * t));
|
|
ctx.setLineDash([]);
|
|
ctx.beginPath();
|
|
ctx.arc((r + smallAmp * Math.cos(omegaR * t)) * Math.cos(omegaTheta * t) + xPos, (r + smallAmp * Math.cos(omegaR * t)) * Math.sin(omegaTheta * t) + yPos, 5, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.beginPath();
|
|
ctx.moveTo(r + smallAmp + xPos, yPos);
|
|
for (i = 0; i < xPositions.length; i++)
|
|
{
|
|
ctx.lineTo(xPositions[i] + xPos, yPositions[i] + yPos);
|
|
}
|
|
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, -1);
|
|
}, 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> |