-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::f64::consts::PI; | ||
|
||
use animation_api::Animation; | ||
use animation_utils::decorators::{BrightnessControlled, SpeedControlled}; | ||
use animation_utils::ParameterSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
|
||
#[derive(Clone, Serialize, Deserialize, ParameterSchema)] | ||
pub struct Parameters { | ||
#[schema_field(name = "Color A", color)] | ||
color_a: lightfx::Color, | ||
|
||
#[schema_field(name = "Color B", color)] | ||
color_b: lightfx::Color, | ||
|
||
#[schema_field(name = "Density", number(min = 0.1, max = 8.0, step = 0.1))] | ||
density: f64, | ||
} | ||
|
||
impl Default for Parameters { | ||
fn default() -> Self { | ||
Self { | ||
density: 1.0, | ||
color_a: lightfx::Color::white(), | ||
color_b: lightfx::Color::rgb(0, 0, 255), | ||
} | ||
} | ||
} | ||
|
||
#[animation_utils::plugin] | ||
pub struct RainbowWaterfall { | ||
points_height: Vec<f64>, | ||
time: f64, | ||
parameters: Parameters, | ||
} | ||
|
||
impl RainbowWaterfall { | ||
pub fn create(points: Vec<(f64, f64, f64)>) -> impl Animation { | ||
SpeedControlled::new(BrightnessControlled::new(Self { | ||
parameters: Default::default(), | ||
time: 0.0, | ||
points_height: points.into_iter().map(|(_, h, _)| h).collect(), | ||
})) | ||
} | ||
} | ||
|
||
impl Animation for RainbowWaterfall { | ||
type Parameters = Parameters; | ||
|
||
fn update(&mut self, delta: f64) { | ||
self.time += delta; | ||
} | ||
|
||
fn render(&self) -> lightfx::Frame { | ||
self.points_height | ||
.iter() | ||
.map(|h| { | ||
(PI * (h * self.parameters.density / 2.0 + self.time)) | ||
.sin() | ||
.powi(2) | ||
}) | ||
.map(|p| { | ||
self.parameters | ||
.color_a | ||
.with_alpha(p) | ||
.blend(&self.parameters.color_b.with_alpha(1.0)) | ||
.apply_alpha() | ||
}) | ||
.into() | ||
} | ||
|
||
fn animation_name(&self) -> &str { | ||
"Waterfall" | ||
} | ||
|
||
fn set_parameters(&mut self, parameters: Self::Parameters) { | ||
self.parameters = parameters; | ||
} | ||
|
||
fn get_parameters(&self) -> Self::Parameters { | ||
self.parameters.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"display_name": "Waterfall" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../target/release/waterfall |