From 5ae3fe8774d845079591056ed71033162081e3a1 Mon Sep 17 00:00:00 2001 From: kbrannen Date: Fri, 21 Apr 2023 00:37:09 -0500 Subject: [PATCH] small fixes to make code look better --- 13_Bounce/perl/bounce.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/13_Bounce/perl/bounce.pl b/13_Bounce/perl/bounce.pl index 0d799514..4aeacf1f 100755 --- a/13_Bounce/perl/bounce.pl +++ b/13_Bounce/perl/bounce.pl @@ -62,7 +62,6 @@ while (1) # draw graph for (my $height=int(-16.0 * ($velocity / 32.0) ** 2.0 + $velocity ** 2.0 / 32.0 + .5) ; $height >= 0 ; $height -= .5) { - #print "h=$height\n"; # kevin if (int($height) == $height) { print sprintf("%2d", $height); } else { print " "; } $line_pos = 0; @@ -73,8 +72,10 @@ while (1) for ($time=0 ; $time <= $T[$i] ; $time += $time_inc) { $line_pos += $time_inc; - next if (abs($height - (.5 * (-32) * $time ** 2.0 + $velocity * $coeff_elas ** ($i - 1) * $time)) > .25); - $curr_line = line_tab($curr_line, ($line_pos / $time_inc), "0"); + if (abs($height - (.5 * (-32) * $time ** 2.0 + $velocity * $coeff_elas ** ($i - 1) * $time)) <= .25) + { + $curr_line = line_tab($curr_line, ($line_pos / $time_inc), "0"); + } } $time = ($T[$i + 1] // 0) / 2; # we can reach 1 past the end, use 0 if that happens last if (-16.0 * $time ** 2.0 + $velocity * $coeff_elas ** ($i - 1) * $time < $height); @@ -82,11 +83,15 @@ while (1) print "$curr_line\n"; } + # draw scale print " ."; print "." x (int($line_pos + 1) / $time_inc + 1), "\n"; print " 0"; my $curr_line = ""; - for my $i (1 .. int($line_pos + .9995)) { $curr_line = line_tab($curr_line, int($i / $time_inc), $i); } + for my $i (1 .. int($line_pos + .9995)) + { + $curr_line = line_tab($curr_line, int($i / $time_inc), $i); + } print "$curr_line\n"; print " " x (int($line_pos + 1) / (2 * $time_inc) - 2), "SECONDS\n\n"; }