2 releases
0.1.1 | Apr 21, 2019 |
---|---|
0.1.0 | Apr 21, 2019 |
#10 in #continuously
7KB
67 lines
Meander
The Meander
crate provides a way to continuously vary the values of an arbitrary number of parameters.
See the documentation for more details.
lib.rs
:
This crate provides a way to show slow change in several variables at once. This change is done in such a way that should explore the value space fairly well while also appearing natural and random.
One place this might be useful is in code that demonstrates how changing certain parameters changes a model.
The variables yielded by this crate will all have values between 0 and 1, so you should scale them to suit your purposes.
How it Works
For each variable, there is a separate function that determines its motion. This function is given by the average of three sinusoidal functions.
use meander::rand;
use meander::typenum::U3;
use meander::Meander;
struct Color {
r: u8,
g: u8,
b: u8,
}
fn random_colors() -> impl Iterator<Item=Color> {
rand::random::<Meander<U3>>()
.into_time_steps(0.01).map(|a| {
match a.as_slice() {
// The variables yielded by `Meander` are floats between 0 and 1,
// so we multiply by 256 and cast to `u8` to get the range we want.
&[r, g, b] => Color {
r: (r*256.0) as u8,
g: (g*256.0) as u8,
b: (b*256.0) as u8,
},
_ => unreachable!()
}
})
}
Dependencies
~0.8–1MB
~16K SLoC