mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 06:43:06 -08:00
Merge pull request #623 from AnthonyMichaelTDM/rust-port-sine-wave
rust port of 78_sine_wave
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Ruby](https://www.ruby-lang.org/en/)
|
||||
|
||||
Converted to Ruby (with tons of inspiration from the Python version) by @marcheiligers
|
||||
|
||||
Run `ruby amazing.rb`.
|
||||
|
||||
Run `DEBUG=1 ruby amazing.ruby` to see how it works (requires at least Ruby 2.7).
|
||||
Conversion to [Rust](https://www.rust-lang.org/) by Anthony Rubick [AnthonyMichaelTDM](https://github.com/AnthonyMichaelTDM)
|
||||
|
||||
8
78_Sine_Wave/rust/Cargo.toml
Normal file
8
78_Sine_Wave/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
3
78_Sine_Wave/rust/README.md
Normal file
3
78_Sine_Wave/rust/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Rust](https://www.rust-lang.org/) by Anthony Rubick [AnthonyMichaelTDM](https://github.com/AnthonyMichaelTDM)
|
||||
37
78_Sine_Wave/rust/src/main.rs
Normal file
37
78_Sine_Wave/rust/src/main.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
fn main() {
|
||||
let mut ticker:f64 = 0.0;
|
||||
let mut spaces ;
|
||||
|
||||
//pring welcome message
|
||||
welcome();
|
||||
|
||||
//drawing loop
|
||||
loop {
|
||||
//print however many spaces
|
||||
spaces = (26.0 + 25.0*ticker.sin()).round() as i32;
|
||||
for _i in 0..=spaces{
|
||||
print!(" "); //print a space
|
||||
}
|
||||
|
||||
//print Creative or Computing
|
||||
if (ticker.round() as i32) % 2 == 0 {
|
||||
println!("CREATIVE");
|
||||
} else {
|
||||
println!("COMPUTING");
|
||||
}
|
||||
|
||||
//increment ticker
|
||||
ticker += 0.25;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* prints welcome message
|
||||
*/
|
||||
fn welcome() {
|
||||
println!("
|
||||
SINE WAVE
|
||||
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
|
||||
");
|
||||
}
|
||||
Reference in New Issue
Block a user