Preset colored noise.
This commit is contained in:
parent
eb7ac1c1f1
commit
eff04faee4
@ -1,7 +1,7 @@
|
|||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::iter::repeat;
|
use std::iter::repeat_with;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -21,6 +21,17 @@ 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]);
|
||||||
@ -37,19 +48,17 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
|
||||||
let mut frame = repeat(repeat(Color::black()).take(x_size).collect::<Vec<_>>())
|
let mut frame = repeat_with(|| {
|
||||||
.take(y_size)
|
repeat_with(|| pick_color(c0, c1, &mut rng))
|
||||||
.collect::<Vec<_>>();
|
.take(x_size)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.take(y_size)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
loop {
|
loop {
|
||||||
let x = rng.gen_range(0, x_size);
|
let x = rng.gen_range(0, x_size);
|
||||||
let y = rng.gen_range(0, y_size);
|
let y = rng.gen_range(0, y_size);
|
||||||
let c = {
|
let c = pick_color(c0, c1, &mut rng);
|
||||||
if rng.gen::<f64>() < 0.5 {
|
|
||||||
c0.interpolate(c1, rng.gen::<f64>().powf(2.0))
|
|
||||||
} else {
|
|
||||||
Color::black()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
frame[y][x] = c;
|
frame[y][x] = c;
|
||||||
|
|
||||||
let mut buf = Vec::with_capacity(x_size * y_size * 3);
|
let mut buf = Vec::with_capacity(x_size * y_size * 3);
|
||||||
|
Loading…
Reference in New Issue
Block a user