From 3e929e564778e9459d5667e91e52dedd17b37fc4 Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Wed, 21 Feb 2024 01:28:43 +0100 Subject: [PATCH] effects: noise function select --- Cargo.lock | 1 + effects/src/nodes/noise.rs | 19 ++++++++++++------- examples/Cargo.toml | 1 + examples/examples/maglab-dmx-demo.rs | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 191ca86..e84bcf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,6 +382,7 @@ name = "examples" version = "0.1.0" dependencies = [ "anyhow", + "noise", "palette", "photonic", "photonic-effects", diff --git a/effects/src/nodes/noise.rs b/effects/src/nodes/noise.rs index 3ec2c45..0b349b1 100644 --- a/effects/src/nodes/noise.rs +++ b/effects/src/nodes/noise.rs @@ -10,48 +10,53 @@ use photonic_dyn::DynamicNode; // TODO: Hue range #[derive(DynamicNode)] -pub struct Noise { +pub struct Noise { #[photonic(attr)] pub speed: Speed, #[photonic(attr)] pub stretch: Stretch, + + pub noise: F, } -pub struct NoiseNode +pub struct NoiseNode where Speed: Attr, Stretch: Attr, + F: NoiseFn { speed: Speed, stretch: Stretch, position: f64, - noise: noise::Perlin, + noise: F, } -impl NodeDecl for Noise +impl NodeDecl for Noise where Speed: FreeAttrDecl, Stretch: FreeAttrDecl, + F: NoiseFn, { - type Node = NoiseNode; + type Node = NoiseNode; async fn materialize(self, builder: &mut NodeBuilder<'_>) -> Result { return Ok(Self::Node { speed: builder.unbound_attr("speed", self.speed)?, stretch: builder.unbound_attr("stretch", self.stretch)?, position: 0.0, - noise: noise::Perlin::default(), + noise: self.noise, }); } } -impl Node for NoiseNode +impl Node for NoiseNode where Speed: Attr, Stretch: Attr, + F: NoiseFn, { const KIND: &'static str = "noise"; diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 8bd2dc0..85f8850 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -11,6 +11,7 @@ photonic = { workspace = true } anyhow = { workspace = true } tokio = { workspace = true, features = ["full"] } palette = { workspace = true } +noise = "*" photonic-effects = { path = "../effects" } photonic-interface-cli = { path = "../interface-cli" } diff --git a/examples/examples/maglab-dmx-demo.rs b/examples/examples/maglab-dmx-demo.rs index 00d25e5..decb132 100644 --- a/examples/examples/maglab-dmx-demo.rs +++ b/examples/examples/maglab-dmx-demo.rs @@ -36,8 +36,9 @@ async fn main() -> Result<()> { })?; let noise = scene.node("noise", Noise { - speed: 0.005.fixed(), - stretch: 5.0.fixed(), + speed: 0.05.fixed(), + stretch: 1.0.fixed(), + noise: noise::OpenSimplex::default(), })?; // TODO: Add switcher for more animations