diff --git a/87_3-D_Plot/rust/Cargo.lock b/87_3-D_Plot/rust/Cargo.lock new file mode 100644 index 000000000..b21cc6a2d --- /dev/null +++ b/87_3-D_Plot/rust/Cargo.lock @@ -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" diff --git a/87_3-D_Plot/rust/Cargo.toml b/87_3-D_Plot/rust/Cargo.toml new file mode 100644 index 000000000..7d75412a6 --- /dev/null +++ b/87_3-D_Plot/rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/87_3-D_Plot/rust/src/main.rs b/87_3-D_Plot/rust/src/main.rs new file mode 100644 index 000000000..ebd66dfa2 --- /dev/null +++ b/87_3-D_Plot/rust/src/main.rs @@ -0,0 +1,68 @@ +/** 3D Plot GAME + * https://github.com/coding-horror/basic-computer-games/blob/main/87_3-D_Plot/3dplot.bas + * Direct conversion from BASIC to Rust by Pablo Marques (marquesrs). + * No additional features or improvements were added. As a faithful translation, + * many of the code here are done in an unrecommended way by today's standards. + * 03/03/25 +*/ + +fn main() { + //1 PRINT TAB(32);"3D PLOT" + //2 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" + //3 PRINT:PRINT:PRINT + print!("{}", + format!("{}{}\n{}{}\n\n\n\n", + " ".repeat(31), + "3D PLOT", + " ".repeat(14), + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" + ) + ); + + //5 DEF FNA(Z)=30*EXP(-Z*Z/100) + let fna = |z: f32| {30.0 * f32::exp(-z*z/100.0)}; + + //100 PRINT + println!(); + + let mut line_content = String::new(); + //110 FOR X=-30 TO 30 STEP 1.5 + let mut x = -30.0; + while x <= 30.0 { + //120 L=0 + let mut l = 0; + + //130 Y1=5*INT(SQR(900-X*X)/5) + let y1 = 5.0 * (f32::sqrt(900.0-x*x)/5.0).floor(); + + //140 FOR Y=Y1 TO -Y1 STEP -5 + let mut y = y1; + while y >= -y1 { + //150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y) + let z = (25.0 + fna(f32::sqrt(x*x+y*y))-0.7*y) as i32; + + //160 IF Z<=L THEN 190 + if z <= l { + y = y - 5.0; + continue; + } + //170 L=Z + l = z; + //180 PRINT TAB(Z);"*"; + while (line_content.len() as i32) < (z-1) { + line_content += " "; + } + line_content += "*"; + //190 NEXT Y + y = y - 5.0; + } + print!("{}", line_content); + line_content.clear(); + + //200 PRINT + println!(); + //210 NEXT X + x = x + 1.5; + } + //300 END +} \ No newline at end of file diff --git a/README.md b/README.md index d7a19ef83..b74523106 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ NOTE: per [the official blog post announcement](https://blog.codinghorror.com/up | 84_Super_Star_Trek | x | x | x | | | | x | | x | x | | 85_Synonym | x | x | x | | | x | x | x | x | x | | 86_Target | x | x | x | | | x | x | | | x | -| 87_3-D_Plot | x | x | x | | | x | x | x | | x | +| 87_3-D_Plot | x | x | x | | | x | x | x | x | x | | 88_3-D_Tic-Tac-Toe | x | | x | | | | x | | | x | | 89_Tic-Tac-Toe | x | x | x | x | | x | x | | x | x | | 90_Tower | x | x | x | | | x | x | | x | x |