1mod utils;
2
3use std::f64::consts::PI;
4use std::process::Command;
5use std::{thread, time::Duration};
6
7pub fn sine_horizontal(display_char: char) {
8 let mut count: f64 = 0.0;
9 utils::hide_cursor();
10 loop {
11 Command::new("clear").status().unwrap();
12 let sine_value = count.sin();
13 let scaled_width = ((sine_value + 1.0) / 2.0) * 80.0;
14 let display_string = std::iter::repeat(display_char)
15 .take(scaled_width as usize)
16 .collect::<String>();
17 println!("{}", display_string);
18 count += 2.0 * PI / 100.0;
19 if count > 2.0 * PI {
20 count -= 2.0 * PI;
21 }
22 thread::sleep(Duration::from_millis(10));
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn it_works() {
32 sine_horizontal('█');
33 }
34}