mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-07 02:24:33 -08:00
rust port of 78_sine_wave
This commit is contained in:
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