This commit is contained in:
marquesrs
2025-02-23 15:08:18 -03:00
parent daa961ebb5
commit e60957ad7e
3 changed files with 173 additions and 0 deletions

7
13_Bounce/rust/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust"
version = "0.1.0"

View File

@@ -0,0 +1,6 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
[dependencies]

160
13_Bounce/rust/src/main.rs Normal file
View File

@@ -0,0 +1,160 @@
use std::io::Write;
fn input(msg: &str) -> String {
print!("{}", msg);
let _ =std::io::stdout().flush().unwrap();
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
return input.trim().to_uppercase();
}
fn main() {
//10 PRINT TAB(33);"BOUNCE"
//20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
//30 PRINT:PRINT:PRINT
print!("{}{}\n{}{}\n\n\n",
" ".repeat(33),
"BOUNCE",
" ".repeat(15),
"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
);
//90 DIM T(20)
let mut t: Vec<f32> = Vec::with_capacity(20);
//100 PRINT "THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY"
//110 PRINT "OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF"
//120 PRINT "ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION"
//130 PRINT "COEFFICIENCY (LESS THAN 1)."
//131 PRINT
//132 PRINT "YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN"
//133 PRINT "'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY)."
//134 PRINT
print!("{}\n{}\n{}\n{}\n\n{}\n{}\n\n",
"THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY",
"OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF",
"ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION",
"COEFFICIENCY (LESS THAN 1).",
"YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN",
"'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY).",
);
loop {
//135 INPUT "TIME INCREMENT (SEC)";S2
let s2 = input("TIME INCREMENT (SEC): ").parse::<f32>().unwrap();
//140 PRINT
println!();
//150 INPUT "VELOCITY (FPS)";V
let v = input("VELOCITY (FPS): ").parse::<f32>().unwrap();
//160 PRINT
println!();
//170 INPUT "COEFFICIENT";C
let c = input("COEFFICIENT: ").parse::<f32>().unwrap();
//180 PRINT
//182 PRINT "FEET"
//184 PRINT
print!("\nFEET\n");
//186 S1=INT(70/(V/(16*S2)))
let s1 = (
70.0 / (v / (16.0 * s2) )
) as i32;
//190 FOR I=1 TO S1
for i in 1..=s1 {
//200 T(I)=V*C^(I-1)/16
t.push(v * c.powf(i as f32 - 1.0) / 16.0);
//210 NEXT I
}
let mut l = 0.0;
//220 FOR H=INT(-16*(V/32)^2+V^2/32+.5) TO 0 STEP -.5
let mut h = ((-16.0*(v/32.0).powf(2.0)) +(v.powf(2.0)/32.0) + 0.5).floor();
while h >= 0.0 {
//221 IF INT(H)<>H THEN 225
if h.floor() != h {
//225 L=0
l = 0.0;
}
else {
//222 PRINT H;
println!("{}", h);
//225 L=0
l = 0.0;
}
//230 FOR I=1 TO S1
for i in 1..=s1 {
let mut t2 = 0.0;
//240 FOR T=0 TO T(I) STEP S2
while t2 <= t[(i - 1) as usize] {
//245 L=L+S2
l = l + s2;
//250 IF ABS(H-(.5*(-32)*T^2+V*C^(I-1)*T))>.25 THEN 270
let condition = h - (0.5 * (-32.0) * t2.powf(2.0) + v * c.powf((i-1) as f32) * t2);
if condition >= 0.25{
continue;
}
//260 PRINT TAB(L/S2);"0";
print!("{}0", " ".repeat((l/s2) as usize));
//270 NEXT T
t2 = t2 + s2;
}
//275 T=T(I+1)/2
t2 = t[i as usize] / 2.0;
//276 IF -16*T^2+V*C^(I-1)*T<H THEN 290
if -16.0*t2.powf(2.0) + v * c.powf(i as f32 -1.0) * t2 <= h {
break;
}
//280 NEXT I
}
//290 PRINT
println!();
//300 NEXT H
h = h - 0.5;
}
//310 PRINT TAB(1);
print!(" ");
//320 FOR I=1 TO INT(L+1)/S2+1
for _ in 1..=((l+1.0).floor() / s2 + 1.0) as i32 {
//330 PRINT ".";
print!(".");
//340 NEXT I
}
//350 PRINT
//355 PRINT " 0";
print!("\n 0");
//360 FOR I=1 TO INT(L+.9995)
for i in 1..=((l + 0.9995) as i32) {
//380 PRINT TAB(INT(I/S2));I;
print!("{}{}", " ".repeat((i as f32 / s2) as usize), i);
//390 NEXT I
}
//400 PRINT
//410 PRINT TAB(INT(L+1)/(2*S2)-2);"SECONDS"
//420 PRINT
let tabs = ((l+1.0).floor() / (2.0 * s2) - 2.0) as usize;
print!("\n{}SECONDS\n", " ".repeat(tabs));
//430 GOTO 135
}
//440 END
}