diff --git a/README.txt b/README.txt index 17dfac7..8a2f71c 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,6 @@ +cnoise - colored noise, sets random pixels in selected colors + paramater is not used yet + bimood - color cycling mood lamp with two complementary colors parameter is the seconds for one cycle through the colors diff --git a/src/bin/cnoise/main.rs b/src/bin/cnoise/main.rs new file mode 100644 index 0000000..1199404 --- /dev/null +++ b/src/bin/cnoise/main.rs @@ -0,0 +1,56 @@ +use std::env::args; +use std::io::stdout; +use std::io::Write; +use std::iter::repeat; +use std::thread::sleep; +use std::time::Duration; + +use rand::thread_rng; +use rand::Rng; + +use pixelfoo::color::Color; + +type Frame = Vec>; + +fn send(w: &mut T, f: &Frame) -> std::io::Result<()> { + for l in f { + for c in l { + w.write_all(&c.rgb())?; + } + } + w.flush() +} + +fn main() -> std::io::Result<()> { + let args = args().collect::>(); + eprintln!("executing {}", args[0]); + + let x_size = args[1].parse::().unwrap(); + let y_size = args[2].parse::().unwrap(); + eprintln!("screen size {}x{}", x_size, y_size); + + let t_frame = 0.040; // s + let delay = Duration::new(0, (1_000_000_000.0 * t_frame) as u32); + + let colors = vec![Color::black(), Color::cyan(), Color::blue()]; + + // time to interpolate from one color to the next + + let mut rng = thread_rng(); + + let mut frame = repeat(repeat(Color::black()).take(x_size).collect::>()) + .take(y_size) + .collect::>(); + loop { + let x = rng.gen_range(0, x_size); + let y = rng.gen_range(0, y_size); + let c = colors[rng.gen_range(0, colors.len())]; + frame[y][x] = c; + + let mut buf = Vec::with_capacity(x_size * y_size * 3); + send(&mut buf, &frame)?; + stdout().write_all(&buf)?; + stdout().flush()?; + sleep(delay); + } +}