Fixed 8-66

This commit is contained in:
2021-09-04 11:49:36 -07:00
parent 686f176265
commit 55f02243c1

View File

@@ -77,12 +77,8 @@
<input type="range" min="30" max="200" value="120" step="0.1" class="greenSlider" id="hSlider"> <input type="range" min="30" max="200" value="120" step="0.1" class="greenSlider" id="hSlider">
<br> <br>
<br> <br>
<t>vy</t> <t>Table x</t>
<input type="range" min="-200" max="200" value="0" step="0.1" class="greenSlider" id="vySlider"> <input type="range" min="-300" max="300" value="100" step="0.1" class="greenSlider" id="tSlider">
<br>
<br>
<t>r</t>
<input type="range" min="5" max="40" value="10" step="0.1" class="greenSlider" id="rSlider">
</div> </div>
<script> <script>
@@ -102,13 +98,11 @@
var omega = 20; var omega = 20;
var theta = 0; var theta = 0;
var r = 10; var r = 10;
var tableX = 100;
var positionsX = [0]; var positionsX = [0];
var positionsY = [110]; var positionsY = [110];
var canBounce = false;
var numBounces = 0;
var maxBounces = 5;
//Relative position of canvas //Relative position of canvas
var xPos = 0; var xPos = -100;
var yPos = -120; var yPos = -120;
//Moves and scales canvas //Moves and scales canvas
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2) ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
@@ -145,15 +139,9 @@
Reset(); Reset();
} }
rSlider.oninput = function() tSlider.oninput = function()
{ {
r = parseFloat(this.value); tableX = parseFloat(this.value);
Reset();
}
vySlider.oninput = function()
{
vy = parseFloat(this.value);
Reset(); Reset();
} }
@@ -189,45 +177,27 @@
positionsX.push(x); positionsX.push(x);
positionsY.push(y); positionsY.push(y);
theta += omega * dt; theta += omega * dt;
if (y <= r - 0.1 && canBounce) if (y <= r - 0.1)
{ {
BounceDown(); BounceDown();
numBounces += 1;
if (numBounces >= maxBounces)
{
canBounce = false;
}
} }
if (y >= h + 0.1 - r && canBounce) if (y >= h + 0.1 - r && y <= h && x > tableX)
{ {
BounceUp(); BounceUp();
numBounces += 1; } else if (y <= h - 0.1 + r && y >= h && x > tableX)
if (numBounces >= maxBounces)
{
canBounce = false;
}
} else if (y < r + 1 && numBounces == 0)
{ {
canBounce = true; BounceDown();
} }
setTimeout(Update, 5); setTimeout(Update, 5);
} }
function Reset() function Reset()
{ {
numBounces = 0;
x = 0; x = 0;
y = parseFloat(document.getElementById("ySlider").value); y = parseFloat(document.getElementById("ySlider").value);
if (y > h - r)
{
canBounce = false;
} else
{
canBounce = true;
}
vy = parseFloat(document.getElementById("vySlider").value);
theta = 0; theta = 0;
vx = parseFloat(document.getElementById("vxSlider").value); vx = parseFloat(document.getElementById("vxSlider").value);
vy = 0;
omega = parseFloat(document.getElementById("wSlider").value); omega = parseFloat(document.getElementById("wSlider").value);
positionsX = [0]; positionsX = [0];
positionsY = [y]; positionsY = [y];
@@ -241,17 +211,9 @@
ctx.lineTo(c.width, yPos); ctx.lineTo(c.width, yPos);
ctx.stroke(); ctx.stroke();
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(-c.width, yPos + h); ctx.moveTo(xPos + tableX, yPos + h);
ctx.lineTo(c.width, yPos + h); ctx.lineTo(c.width, yPos + h);
ctx.stroke(); ctx.stroke();
ctx.fillStyle = "#ffffff";
if (!canBounce)
{
ctx.beginPath();
ctx.arc(xPos + x, yPos + y, r + r, 0, Math.PI * 2);
ctx.fill();
}
ctx.beginPath(); ctx.beginPath();
ctx.arc(xPos + x, yPos + y, r, 0, Math.PI * 2); ctx.arc(xPos + x, yPos + y, r, 0, Math.PI * 2);
ctx.stroke(); ctx.stroke();