Skip to content

Commit dd9f2f6

Browse files
Merge pull request #929 from marquesrs/3D-plot-rust-implementation
Rust implementation for the game 3D Plot
2 parents dfeb48d + 3874260 commit dd9f2f6

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

Diff for: 87_3-D_Plot/rust/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: 87_3-D_Plot/rust/Cargo.toml

+6
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]

Diff for: 87_3-D_Plot/rust/src/main.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/** 3D Plot GAME
2+
* https://github.com/coding-horror/basic-computer-games/blob/main/87_3-D_Plot/3dplot.bas
3+
* Direct conversion from BASIC to Rust by Pablo Marques (marquesrs).
4+
* No additional features or improvements were added. As a faithful translation,
5+
* many of the code here are done in an unrecommended way by today's standards.
6+
* 03/03/25
7+
*/
8+
9+
fn main() {
10+
//1 PRINT TAB(32);"3D PLOT"
11+
//2 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
12+
//3 PRINT:PRINT:PRINT
13+
print!("{}",
14+
format!("{}{}\n{}{}\n\n\n\n",
15+
" ".repeat(31),
16+
"3D PLOT",
17+
" ".repeat(14),
18+
"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
19+
)
20+
);
21+
22+
//5 DEF FNA(Z)=30*EXP(-Z*Z/100)
23+
let fna = |z: f32| {30.0 * f32::exp(-z*z/100.0)};
24+
25+
//100 PRINT
26+
println!();
27+
28+
let mut line_content = String::new();
29+
//110 FOR X=-30 TO 30 STEP 1.5
30+
let mut x = -30.0;
31+
while x <= 30.0 {
32+
//120 L=0
33+
let mut l = 0;
34+
35+
//130 Y1=5*INT(SQR(900-X*X)/5)
36+
let y1 = 5.0 * (f32::sqrt(900.0-x*x)/5.0).floor();
37+
38+
//140 FOR Y=Y1 TO -Y1 STEP -5
39+
let mut y = y1;
40+
while y >= -y1 {
41+
//150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y)
42+
let z = (25.0 + fna(f32::sqrt(x*x+y*y))-0.7*y) as i32;
43+
44+
//160 IF Z<=L THEN 190
45+
if z <= l {
46+
y = y - 5.0;
47+
continue;
48+
}
49+
//170 L=Z
50+
l = z;
51+
//180 PRINT TAB(Z);"*";
52+
while (line_content.len() as i32) < (z-1) {
53+
line_content += " ";
54+
}
55+
line_content += "*";
56+
//190 NEXT Y
57+
y = y - 5.0;
58+
}
59+
print!("{}", line_content);
60+
line_content.clear();
61+
62+
//200 PRINT
63+
println!();
64+
//210 NEXT X
65+
x = x + 1.5;
66+
}
67+
//300 END
68+
}

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ NOTE: per [the official blog post announcement](https://blog.codinghorror.com/up
164164
| 84_Super_Star_Trek | x | x | x | | | | x | | x | x |
165165
| 85_Synonym | x | x | x | | | x | x | x | x | x |
166166
| 86_Target | x | x | x | | | x | x | | | x |
167-
| 87_3-D_Plot | x | x | x | | | x | x | x | | x |
167+
| 87_3-D_Plot | x | x | x | | | x | x | x | x | x |
168168
| 88_3-D_Tic-Tac-Toe | x | | x | | | | x | | | x |
169169
| 89_Tic-Tac-Toe | x | x | x | x | | x | x | | x | x |
170170
| 90_Tower | x | x | x | | | x | x | | x | x |

0 commit comments

Comments
 (0)