Files
loldog/src/main.rs
2016-09-01 14:12:18 +02:00

43 lines
957 B
Rust

extern crate rand;
extern crate ansi_term;
use std::io;
use std::io::prelude::*;
use std::f32::consts::PI;
use rand::{thread_rng, Rng};
use ansi_term::Colour::RGB;
fn main() {
let mut s = 1.0; // thread_rng().gen_range(0.0, 256.0);
let stdin = io::stdin();
for line in stdin.lock().lines() {
s += 1.0;
let mut d = 0;
for c in line.unwrap().chars() {
d += match c {
'\t' => 8,
_ => 1
};
let (red, green, blue) = rainbow(0.1, (s + d as f32) / 3.0);
print!("{}", RGB(red, green, blue).paint(c.to_string()));
}
print!("\n");
}
}
fn rainbow(frec: f32, i: f32) -> (u8, u8, u8) {
let red = (f32::sin(frec * i) * 127.0 + 128.0) as u8;
let green = (f32::sin(frec * i + 2.0 * PI / 3.0) * 127.0 + 128.0) as u8;
let blue = (f32::sin(frec * i + 4.0 * PI / 3.0) * 127.0 + 128.0) as u8;
(red, green, blue)
}