Skip to content

Commit

Permalink
effects: noise function select
Browse files Browse the repository at this point in the history
  • Loading branch information
fooker committed Feb 21, 2024
1 parent 9922d8e commit 3e929e5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions effects/src/nodes/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,53 @@ use photonic_dyn::DynamicNode;
// TODO: Hue range

#[derive(DynamicNode)]
pub struct Noise<Speed, Stretch> {
pub struct Noise<Speed, Stretch, F> {
#[photonic(attr)]
pub speed: Speed,

#[photonic(attr)]
pub stretch: Stretch,

pub noise: F,
}

pub struct NoiseNode<Speed, Stretch>
pub struct NoiseNode<Speed, Stretch, F>
where
Speed: Attr<Value = f32>,
Stretch: Attr<Value = f32>,
F: NoiseFn<f64, 2>
{
speed: Speed,
stretch: Stretch,

position: f64,

noise: noise::Perlin,
noise: F,
}

impl<Speed, Stretch> NodeDecl for Noise<Speed, Stretch>
impl<Speed, Stretch, F> NodeDecl for Noise<Speed, Stretch, F>
where
Speed: FreeAttrDecl<Value = f32>,
Stretch: FreeAttrDecl<Value = f32>,
F: NoiseFn<f64, 2>,
{
type Node = NoiseNode<Speed::Attr, Stretch::Attr>;
type Node = NoiseNode<Speed::Attr, Stretch::Attr, F>;

async fn materialize(self, builder: &mut NodeBuilder<'_>) -> Result<Self::Node> {
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<Speed, Stretch> Node for NoiseNode<Speed, Stretch>
impl<Speed, Stretch, F> Node for NoiseNode<Speed, Stretch, F>
where
Speed: Attr<Value = f32>,
Stretch: Attr<Value = f32>,
F: NoiseFn<f64, 2>,
{
const KIND: &'static str = "noise";

Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
5 changes: 3 additions & 2 deletions examples/examples/maglab-dmx-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e929e5

Please sign in to comment.