Merge pull request #623 from AnthonyMichaelTDM/rust-port-sine-wave

rust port of 78_sine_wave
This commit is contained in:
Jeff Atwood
2022-03-11 11:21:39 -06:00
committed by GitHub
4 changed files with 49 additions and 7 deletions

View File

@@ -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)

View 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]

View 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)

View 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
");
}