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