Skip to content

Commit e60957a

Browse files
committed
init
1 parent daa961e commit e60957a

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

13_Bounce/rust/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

13_Bounce/rust/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

13_Bounce/rust/src/main.rs

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
use std::io::Write;
2+
3+
fn input(msg: &str) -> String {
4+
print!("{}", msg);
5+
let _ =std::io::stdout().flush().unwrap();
6+
let mut input = String::new();
7+
std::io::stdin().read_line(&mut input).unwrap();
8+
return input.trim().to_uppercase();
9+
}
10+
11+
fn main() {
12+
//10 PRINT TAB(33);"BOUNCE"
13+
//20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
14+
//30 PRINT:PRINT:PRINT
15+
print!("{}{}\n{}{}\n\n\n",
16+
" ".repeat(33),
17+
"BOUNCE",
18+
" ".repeat(15),
19+
"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
20+
);
21+
22+
//90 DIM T(20)
23+
let mut t: Vec<f32> = Vec::with_capacity(20);
24+
25+
//100 PRINT "THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY"
26+
//110 PRINT "OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF"
27+
//120 PRINT "ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION"
28+
//130 PRINT "COEFFICIENCY (LESS THAN 1)."
29+
//131 PRINT
30+
//132 PRINT "YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN"
31+
//133 PRINT "'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY)."
32+
//134 PRINT
33+
print!("{}\n{}\n{}\n{}\n\n{}\n{}\n\n",
34+
"THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY",
35+
"OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF",
36+
"ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION",
37+
"COEFFICIENCY (LESS THAN 1).",
38+
"YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN",
39+
"'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY).",
40+
);
41+
42+
loop {
43+
//135 INPUT "TIME INCREMENT (SEC)";S2
44+
let s2 = input("TIME INCREMENT (SEC): ").parse::<f32>().unwrap();
45+
46+
//140 PRINT
47+
println!();
48+
49+
//150 INPUT "VELOCITY (FPS)";V
50+
let v = input("VELOCITY (FPS): ").parse::<f32>().unwrap();
51+
52+
//160 PRINT
53+
println!();
54+
55+
//170 INPUT "COEFFICIENT";C
56+
let c = input("COEFFICIENT: ").parse::<f32>().unwrap();
57+
58+
//180 PRINT
59+
//182 PRINT "FEET"
60+
//184 PRINT
61+
print!("\nFEET\n");
62+
63+
//186 S1=INT(70/(V/(16*S2)))
64+
let s1 = (
65+
70.0 / (v / (16.0 * s2) )
66+
) as i32;
67+
68+
//190 FOR I=1 TO S1
69+
for i in 1..=s1 {
70+
//200 T(I)=V*C^(I-1)/16
71+
t.push(v * c.powf(i as f32 - 1.0) / 16.0);
72+
//210 NEXT I
73+
}
74+
75+
let mut l = 0.0;
76+
77+
//220 FOR H=INT(-16*(V/32)^2+V^2/32+.5) TO 0 STEP -.5
78+
let mut h = ((-16.0*(v/32.0).powf(2.0)) +(v.powf(2.0)/32.0) + 0.5).floor();
79+
while h >= 0.0 {
80+
//221 IF INT(H)<>H THEN 225
81+
if h.floor() != h {
82+
//225 L=0
83+
l = 0.0;
84+
}
85+
else {
86+
//222 PRINT H;
87+
println!("{}", h);
88+
//225 L=0
89+
l = 0.0;
90+
}
91+
92+
//230 FOR I=1 TO S1
93+
for i in 1..=s1 {
94+
let mut t2 = 0.0;
95+
//240 FOR T=0 TO T(I) STEP S2
96+
while t2 <= t[(i - 1) as usize] {
97+
//245 L=L+S2
98+
l = l + s2;
99+
100+
//250 IF ABS(H-(.5*(-32)*T^2+V*C^(I-1)*T))>.25 THEN 270
101+
let condition = h - (0.5 * (-32.0) * t2.powf(2.0) + v * c.powf((i-1) as f32) * t2);
102+
if condition >= 0.25{
103+
continue;
104+
}
105+
//260 PRINT TAB(L/S2);"0";
106+
print!("{}0", " ".repeat((l/s2) as usize));
107+
108+
//270 NEXT T
109+
t2 = t2 + s2;
110+
}
111+
112+
//275 T=T(I+1)/2
113+
t2 = t[i as usize] / 2.0;
114+
115+
//276 IF -16*T^2+V*C^(I-1)*T<H THEN 290
116+
if -16.0*t2.powf(2.0) + v * c.powf(i as f32 -1.0) * t2 <= h {
117+
break;
118+
}
119+
120+
//280 NEXT I
121+
}
122+
123+
//290 PRINT
124+
println!();
125+
126+
//300 NEXT H
127+
h = h - 0.5;
128+
}
129+
130+
//310 PRINT TAB(1);
131+
print!(" ");
132+
133+
//320 FOR I=1 TO INT(L+1)/S2+1
134+
for _ in 1..=((l+1.0).floor() / s2 + 1.0) as i32 {
135+
//330 PRINT ".";
136+
print!(".");
137+
//340 NEXT I
138+
}
139+
140+
//350 PRINT
141+
//355 PRINT " 0";
142+
print!("\n 0");
143+
144+
//360 FOR I=1 TO INT(L+.9995)
145+
for i in 1..=((l + 0.9995) as i32) {
146+
//380 PRINT TAB(INT(I/S2));I;
147+
print!("{}{}", " ".repeat((i as f32 / s2) as usize), i);
148+
//390 NEXT I
149+
}
150+
151+
//400 PRINT
152+
//410 PRINT TAB(INT(L+1)/(2*S2)-2);"SECONDS"
153+
//420 PRINT
154+
let tabs = ((l+1.0).floor() / (2.0 * s2) - 2.0) as usize;
155+
print!("\n{}SECONDS\n", " ".repeat(tabs));
156+
157+
//430 GOTO 135
158+
}
159+
//440 END
160+
}

0 commit comments

Comments
 (0)