Skip to content

Commit

Permalink
collect the color strings
Browse files Browse the repository at this point in the history
  • Loading branch information
BlinkyStitt committed Apr 27, 2024
1 parent ecee070 commit 86cf2c7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions musical-leptos/src/components/dancing_lights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ pub fn DancingLights() -> impl IntoView {
// TODO: use a signal for this so that we can change it real time
let gradient = Gradient::<NUM_CHANNELS>::new_rainbow(100.0, 70.0);

let colors: Vec<_> = gradient
.colors
.iter()
.map(|x| format!("#{:02X}{:02X}{:02X}", x.r, x.g, x.b))
.collect();

// // TODO: make this a signal so the user can change it?
// let peak_decay = 0.99;

Expand Down Expand Up @@ -195,7 +201,7 @@ pub fn DancingLights() -> impl IntoView {
// >
// <li>{data.1}</li>
// </For>
{audio().into_iter().enumerate().map(|(i, x)| audio_list_item(&gradient, i, (x * 8.0) as u8)).collect_view()}
{audio().into_iter().enumerate().map(|(i, x)| audio_list_item(&colors[i], (x * 8.0) as u8)).collect_view()}
</div>

<p>Input ID: { media_stream_id }</p>
Expand All @@ -209,12 +215,7 @@ pub fn DancingLights() -> impl IntoView {
}

/// TODO: i think this should be a component, but references make that unhappy
pub fn audio_list_item<const N: usize>(gradient: &Gradient<N>, i: usize, x: u8) -> impl IntoView {
let color = gradient.colors[i];

// TODO: i'm sure there is a better way to do this
let color = format!("#{:02X}{:02X}{:02X}", color.r, color.g, color.b);

pub fn audio_list_item(color: &str, x: u8) -> impl IntoView {
let text = match x {
0 => "󠀠",
1 => "M",
Expand All @@ -226,7 +227,8 @@ pub fn audio_list_item<const N: usize>(gradient: &Gradient<N>, i: usize, x: u8)
7 => "MERBOTS ",
8 => "MERBOTS!",
_ => {
warn!("unexpected length for #{}! {}", i, x);
// TODO: we used to have the index here. i think we want that back
warn!("unexpected length for {}! {}", color, x);
"ERROR!!!!"
}
};
Expand Down

0 comments on commit 86cf2c7

Please sign in to comment.