MAINT: Apply pre-commit

Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
This commit is contained in:
Martin Thoma
2022-03-05 09:29:23 +01:00
parent f5e33ae38f
commit e64fb6795c
536 changed files with 6267 additions and 5556 deletions

View File

@@ -9,52 +9,52 @@ import java.lang.Math;
* <p>
* Note: The idea was to create a version of the 1970's BASIC game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*
*
* Converted from BASIC to Java by Darren Cardenas.
*/
public class Bounce {
public class Bounce {
private final Scanner scan; // For user input
public Bounce() {
scan = new Scanner(System.in);
} // End of constructor Bounce
public void play() {
public Bounce() {
scan = new Scanner(System.in);
} // End of constructor Bounce
public void play() {
showIntro();
startGame();
} // End of method play
private void showIntro() {
} // End of method play
private void showIntro() {
System.out.println(" ".repeat(32) + "BOUNCE");
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n");
} // End of method showIntro
private void startGame() {
private void startGame() {
double coefficient = 0;
double height = 0;
double height = 0;
double timeIncrement = 0;
double timeIndex = 0;
double timeTotal = 0;
double velocity = 0;
double velocity = 0;
double[] timeData = new double[21];
int heightInt = 0;
int index = 0;
int maxData = 0;
String lineContent = "";
System.out.println("THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY");
System.out.println("OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF");
System.out.println("ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION");
@@ -63,107 +63,107 @@ public class Bounce {
System.out.println("YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN");
System.out.println("'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY).");
System.out.println("");
// Begin outer while loop
while (true) {
System.out.print("TIME INCREMENT (SEC)? ");
timeIncrement = Double.parseDouble(scan.nextLine());
System.out.println("");
System.out.print("VELOCITY (FPS)? ");
velocity = Double.parseDouble(scan.nextLine());
velocity = Double.parseDouble(scan.nextLine());
System.out.println("");
System.out.print("COEFFICIENT? ");
coefficient = Double.parseDouble(scan.nextLine());
coefficient = Double.parseDouble(scan.nextLine());
System.out.println("");
System.out.println("FEET");
System.out.println("");
maxData = (int)(70 / (velocity / (16 * timeIncrement)));
for (index = 1; index <= maxData; index++) {
for (index = 1; index <= maxData; index++) {
timeData[index] = velocity * Math.pow(coefficient, index - 1) / 16;
}
// Begin loop through all rows of y-axis data
for (heightInt = (int)(-16 * Math.pow(velocity / 32, 2) + Math.pow(velocity, 2) / 32 + 0.5) * 10;
for (heightInt = (int)(-16 * Math.pow(velocity / 32, 2) + Math.pow(velocity, 2) / 32 + 0.5) * 10;
heightInt >= 0; heightInt -= 5) {
height = heightInt / 10.0;
lineContent = "";
if ((int)(Math.floor(height)) == height) {
lineContent += " " + (int)(height) + " ";
}
timeTotal = 0;
for (index = 1; index <= maxData; index++) {
}
timeTotal = 0;
for (index = 1; index <= maxData; index++) {
for (timeIndex = 0; timeIndex <= timeData[index]; timeIndex += timeIncrement) {
timeTotal += timeIncrement;
if (Math.abs(height - (0.5 * (-32) * Math.pow(timeIndex, 2) + velocity
if (Math.abs(height - (0.5 * (-32) * Math.pow(timeIndex, 2) + velocity
* Math.pow(coefficient, index - 1) * timeIndex)) <= 0.25) {
while (lineContent.length() < (timeTotal / timeIncrement) - 1) {
lineContent += " ";
}
lineContent += "0";
}
while (lineContent.length() < (timeTotal / timeIncrement) - 1) {
lineContent += " ";
}
lineContent += "0";
}
}
timeIndex = timeData[index + 1] / 2;
if (-16 * Math.pow(timeIndex, 2) + velocity * Math.pow(coefficient, index - 1) * timeIndex < height) {
break;
}
}
break;
}
}
System.out.println(lineContent);
} // End loop through all rows of y-axis data
lineContent = "";
// Show the x-axis
for (index = 1; index <= (int)(timeTotal + 1) / timeIncrement + 1; index++) {
lineContent += ".";
lineContent += ".";
}
System.out.println(lineContent);
lineContent = " 0";
for (index = 1; index <= (int)(timeTotal + 0.9995); index++) {
while (lineContent.length() < (int)(index / timeIncrement)) {
lineContent += " ";
}
lineContent += index;
while (lineContent.length() < (int)(index / timeIncrement)) {
lineContent += " ";
}
lineContent += index;
}
System.out.println(lineContent);
System.out.println(" ".repeat((int)((timeTotal + 1) / (2 * timeIncrement) - 3)) + "SECONDS");
} // End outer while loop
System.out.println(" ".repeat((int)((timeTotal + 1) / (2 * timeIncrement) - 3)) + "SECONDS");
} // End outer while loop
} // End of method startGame
} // End of method startGame
public static void main(String[] args) {
Bounce game = new Bounce();
game.play();
} // End of method main
} // End of class Bounce

View File

@@ -12,10 +12,10 @@ function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");

View File

@@ -61,7 +61,7 @@ def run_simulation(delta_t, v0, coeff_rest):
t[i] = v0 * coeff_rest ** (i - 1) / 16
# Draw the trajectory of the bouncing ball, one slice of height at a time
h = int(-16 * (v0 / 32) ** 2 + v0 ** 2 / 32 + 0.5)
h = int(-16 * (v0 / 32) ** 2 + v0**2 / 32 + 0.5)
while h >= 0:
line = ""
if int(h) == h:
@@ -72,14 +72,14 @@ def run_simulation(delta_t, v0, coeff_rest):
while tm <= t[i]:
l += delta_t
if (
abs(h - (0.5 * (-32) * tm ** 2 + v0 * coeff_rest ** (i - 1) * tm))
abs(h - (0.5 * (-32) * tm**2 + v0 * coeff_rest ** (i - 1) * tm))
<= 0.25
):
line = print_at_tab(line, int(l / delta_t), "0")
tm += delta_t
tm = t[i + 1] / 2
if -16 * tm ** 2 + v0 * coeff_rest ** (i - 1) * tm < h:
if -16 * tm**2 + v0 * coeff_rest ** (i - 1) * tm < h:
break
print(line)
h = h - 0.5

View File

@@ -108,7 +108,7 @@ def plot_bouncing_ball(strobbing_time, v0, c)
# skipped by line 98
plot_width += 1 if plotted_height == 0
}
if heighest_position_in_next_bounce(time_in_bounce, v0, i, c) < plotted_height then
# If we got no more ball positions at or above current height in the next bounce,
# we can skip the rest of the bounces and move down to the next height to plot