Make chars more colorful.

This commit is contained in:
Juergen Stuber 2018-12-31 21:02:06 +01:00
parent 75ca3a28e5
commit f5a2f12990
1 changed files with 20 additions and 27 deletions

View File

@ -3,7 +3,7 @@ use std::fs::File;
use std::io::stdout; use std::io::stdout;
use std::io::Read; use std::io::Read;
use std::io::Write; use std::io::Write;
use std::iter::repeat_with; use std::iter::repeat;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
@ -23,17 +23,6 @@ fn send<T: Write>(w: &mut T, f: &Frame) -> std::io::Result<()> {
w.flush() w.flush()
} }
fn pick_color<R>(c0: Color, c1: Color, rng: &mut R) -> Color
where
R: Rng,
{
if rng.gen::<f64>() < 0.5 {
c0.interpolate(c1, rng.gen::<f64>().powf(2.0))
} else {
Color::black()
}
}
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
let args = args().collect::<Vec<_>>(); let args = args().collect::<Vec<_>>();
eprintln!("executing {}", args[0]); eprintln!("executing {}", args[0]);
@ -49,32 +38,36 @@ fn main() -> std::io::Result<()> {
let t_frame = 0.040; // s let t_frame = 0.040; // s
let delay = Duration::new(0, (1_000_000_000.0 * t_frame) as u32); let delay = Duration::new(0, (1_000_000_000.0 * t_frame) as u32);
let c0 = Color::new(0, 138, 170);
let c1 = Color::new(0, 160, 95);
let mut rng = thread_rng(); let mut rng = thread_rng();
let mut frame = repeat_with(|| { let colors = vec![
repeat_with(|| pick_color(c0, c1, &mut rng)) Color::black(),
.take(x_size) Color::red(),
.collect::<Vec<_>>() Color::green(),
}) Color::blue(),
.take(y_size) Color::yellow(),
.collect::<Vec<_>>(); Color::cyan(),
Color::magenta(),
Color::white(),
];
let mut frame = repeat(repeat(Color::black()).take(x_size).collect::<Vec<_>>())
.take(y_size)
.collect::<Vec<_>>();
loop { loop {
if rng.gen::<f64>() < 0.01 { if rng.gen::<f64>() < 0.02 {
let x = rng.gen_range(0, x_size / 8); let x = rng.gen_range(0, x_size / 8);
let y = rng.gen_range(0, y_size / 8); let y = rng.gen_range(0, y_size / 8);
let color = pick_color(c0, c1, &mut rng); let fg = colors[rng.gen_range(0, colors.len())];
let bg = colors[rng.gen_range(0, colors.len())];
let start_index = rng.gen_range(0, buffer.len() / 8) * 8; let start_index = rng.gen_range(0, buffer.len() / 8) * 8;
for i in 0..8 { for i in 0..8 {
let b = buffer[start_index + i]; let b = buffer[start_index + i];
for j in 0..8 { for j in 0..8 {
frame[y * 8 + i][x * 8 + j] = { frame[y * 8 + 7 - i][x * 8 + j] = {
if b & (1 << j) != 0 { if b & (1 << j) != 0 {
color fg
} else { } else {
Color::black() bg
} }
}; };
} }