mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
generate random color for each phrase
This commit is contained in:
parent
79ee7081e6
commit
69a81106fc
4 changed files with 176 additions and 11 deletions
|
|
@ -51,6 +51,8 @@ pub struct Phrase {
|
|||
pub loop_length: usize,
|
||||
/// All notes are displayed with minimum length
|
||||
pub percussive: bool,
|
||||
/// Identifying color of phrase
|
||||
pub color: Color,
|
||||
}
|
||||
/// Contains state for viewing and editing a phrase
|
||||
pub struct PhraseEditor<E: Engine> {
|
||||
|
|
@ -156,8 +158,25 @@ impl Default for Phrase {
|
|||
}
|
||||
impl Phrase {
|
||||
pub fn new (
|
||||
name: &str, loop_on: bool, length: usize, notes: Option<PhraseData>
|
||||
name: &str,
|
||||
loop_on: bool,
|
||||
length: usize,
|
||||
notes: Option<PhraseData>
|
||||
) -> Self {
|
||||
use rand::{thread_rng, prelude::*};
|
||||
use palette::{*, convert::*, okhsl::*};
|
||||
let mut rng = thread_rng();
|
||||
let color: Okhsl<f32> = Okhsl::new(
|
||||
rng.gen::<f32>() * 360f32 - 180f32,
|
||||
rng.gen::<f32>() * 0.5 + 0.25,
|
||||
rng.gen::<f32>() * 0.5 + 0.25,
|
||||
);
|
||||
let color: Srgb<f32> = Srgb::from_color_unclamped(color);
|
||||
let color = Color::Rgb(
|
||||
(color.red * 255.0) as u8,
|
||||
(color.green * 255.0) as u8,
|
||||
(color.blue * 255.0) as u8,
|
||||
);
|
||||
Self {
|
||||
uuid: uuid::Uuid::new_v4(),
|
||||
name: Arc::new(RwLock::new(name.into())),
|
||||
|
|
@ -168,6 +187,7 @@ impl Phrase {
|
|||
loop_start: 0,
|
||||
loop_length: length,
|
||||
percussive: true,
|
||||
color
|
||||
}
|
||||
}
|
||||
pub fn toggle_loop (&mut self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue