use termion;
use std::{thread, time::{self, Duration}, env};
use round;
use colored::{ColoredString, Colorize};
fn main() {
let t = time::Instant::now();
let args: Vec<String> = env::args().collect::<Vec<String>>()[1..].to_vec();
let mut points = Vec::new();
let mut shifts = Vec::new();
let mut cols: Vec<(u8,u8,u8)> = Vec::new();
for i in 0..args.len() {
let l10 = [0;10];
points.push(l10);
shifts.push(round::round((i as f64 / args.len() as f64) * 628.0, 0) as usize);
cols.push(get_col(&args[i]));
}
let x:usize = termion::terminal_size().unwrap().0 as usize;
let mut string = vec![0;x];
loop {
string = vec![0;x];
for index in 0..points.len() {
let i = &points[index];
(string, points[index]) = add_on_str(t, &mut string, i, x, &shifts[index]);
}
let out = print_format(&string, &cols);
thread::sleep(time::Duration::from_millis(10));
println!("{out}");
}
}
fn print_format(l: &Vec<u8>, cols: &Vec<(u8,u8,u8)>) -> String {
return l.into_iter().map(|x|
if *x == 0 { format!("{}", ColoredString::from(" ")) }
else {
let mut o = format!("{}", ColoredString::from(" "));
for c in 0..cols.len() {
if (x - 1) / 2 == c as u8 {
if x % 2 == 0 {
o = format!("{}", "0".truecolor(cols[c].0,cols[c].1,cols[c].2))
} else {
o = format!("{}", "-".truecolor(cols[c].0,cols[c].1,cols[c].2))
}
}
}
o
}
).collect::<String>();
}
fn get_col(s: &String) -> (u8,u8,u8) {
let m = &*s.to_lowercase();
let m = m.trim();
match m {
"red" | "r" => (230, 25, 25),
"green" | "g" => (0,255,0),
"blue" | "b" => (59, 121, 229),
"white" | "w"=> (200,200,200),
"black" | "k"=> (0,0,0),
"purple" | "p" => (152, 19, 209),
_ => todo!(),
}
}
fn add_on_str(now: time::Instant, base: &Vec<u8>, addition: &[usize;10], x: usize, shift: &usize) -> (Vec<u8>, [usize;10]) {
let raw_sin = f64::sin(now.elapsed().as_millis() as f64 / 200.0 + *shift as f64 / 100.0) / 2. + 0.5;
let pos:usize = round::round(raw_sin * (x-1) as f64, 0) as usize;
let mut add_out = [0;10];
let mut base_out = base.clone();
for i in 0..9 {
add_out[i] = addition[i + 1];
}
add_out[9] = pos;
let dash_num:u8 = get_biggest(base) + 1;
let point_num:u8 = dash_num + 1;
for i in &addition[..addition.len() - 1] {
if base[*i] != 0 {
if base[*i]%2 != 0 {
base_out[*i] = dash_num;
}
} else if base[*i] == 0 {
base_out[*i] = dash_num;
}
}
base_out[addition[9]] = point_num;
(base_out, add_out)
}
fn change_point(now: time::Instant, lt: &mut [usize;11], x: usize) {
let raw_sin = f64::sin(now.elapsed().as_millis() as f64 / 200.0 + lt[10] as f64 / 100.0) / 2. + 0.5;
let pos:usize = round::round(raw_sin * (x-1) as f64, 0) as usize;
let mut out = [0;11];
for i in 0..9 {
out[i] = lt[i + 1];
println!("{}",lt[i+2]);
}
out[9] = pos;
out[10] = lt[10];
*lt = out;
}
fn get_biggest(x: &Vec<u8>) -> u8{
let mut largest = &0;
for i in x{
if i > largest {
largest = i;
}
}
*largest
}
fn to_str(l:Vec<char>, c1: (u8,u8,u8), c2: (u8,u8,u8)) -> String {
return l.into_iter().map(|x|
if x == 's' { format!("{}","0".to_string().truecolor(c1.0,c1.1,c1.2)) }
else if x == 'c' { format!("{}","0".to_string().truecolor(c2.0,c2.1,c2.2)) }
else if x == '-' { format!("{}","-".to_string().truecolor(c1.0,c1.1,c1.2)) }
else if x == '`' { format!("{}","-".to_string().truecolor(c2.0,c2.1,c2.2)) }
else { " ".to_string() }
).collect::<String>();
}
fn to_str_basic(l:Vec<char>, c: (u8,u8,u8)) -> String{
return l.into_iter().map(|x| if x == '0' { format!("{}", "0".to_string().truecolor(c.0, c.1, c.2)) } else if x == '-' { format!("{}", "-".to_string().truecolor(c.0,c.1,c.2)) } else { format!("{}", ColoredString::from(" "))} ).collect::<String>();
}