2 个版本
| 0.1.1 | 2019年4月21日 | 
|---|---|
| 0.1.0 | 2019年4月21日 | 
#10 in #continuously
7KB
67 行
Meander
Meander 库提供了一种连续改变任意数量参数值的方法。
有关详细信息,请参阅文档。
lib.rs:
此库提供了一种同时展示多个变量缓慢变化的方法。这种变化方式旨在较好地探索值空间,同时看起来自然且随机。
这可能在一个演示如何改变某些参数以改变模型的代码中非常有用。
此库生成的变量值将在 0 和 1 之间,因此您应将其缩放以适应您的需求。
工作原理
对于每个变量,都有一个单独的函数来确定其运动。该函数由三个正弦函数的平均值给出。
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!()
            }
        })
}
依赖关系
~0.8–1MB
~16K SLoC