fix rand
This commit is contained in:
parent
7dacd45610
commit
48dee090d3
2 changed files with 9 additions and 4 deletions
|
@ -4,7 +4,7 @@ use rs_ws281x::WS2811Error;
|
|||
// use std::{thread, time};
|
||||
|
||||
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
||||
// println!("Value: {:?}", values[0]);
|
||||
//println!("Value: {:?}", values[0]);
|
||||
//thread::sleep(time::Duration::from_millis(10));
|
||||
let channels: Vec<usize> = controller.channels();
|
||||
let strip = controller.leds_mut(channels[0]);
|
||||
|
|
|
@ -133,22 +133,26 @@ impl Pattern for Random {
|
|||
fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>, _ticks: u64) {
|
||||
use rand::prelude::*;
|
||||
let mut rng = rand::thread_rng();
|
||||
for x in 0..values.len() {
|
||||
let mut color = (*values)[x];
|
||||
for i in 0..values.len() {
|
||||
let mut color = (*values)[i];
|
||||
let min = self.min;
|
||||
let max = self.max;
|
||||
if self.r {
|
||||
let y: f64 = rng.gen();
|
||||
color[2] = (y * (max - min) as f64) as u8 + min;
|
||||
//println!("r {} {}", y, color[2]);
|
||||
}
|
||||
if self.g {
|
||||
let y: f64 = rng.gen();
|
||||
color[1] = (y * (max - min) as f64) as u8 + min;
|
||||
//println!("g {} {}", y, color[1]);
|
||||
}
|
||||
if self.b {
|
||||
let y: f64 = rng.gen();
|
||||
color[0] = (y * (max - min) as f64) as u8 + min;
|
||||
//println!("b {} {}", y, color[0]);
|
||||
}
|
||||
(*values)[i] = color;
|
||||
}
|
||||
}
|
||||
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
||||
|
@ -172,7 +176,7 @@ impl Pattern for Random {
|
|||
}
|
||||
}
|
||||
};
|
||||
for x in 1..end {
|
||||
for x in 0..end+1 {
|
||||
match args[x].as_str() {
|
||||
"r" => {r = true;},
|
||||
"g" => {g = true;},
|
||||
|
@ -180,6 +184,7 @@ impl Pattern for Random {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
//println!("{} {} {}", r,g,b);
|
||||
Ok(Random {
|
||||
r: r,
|
||||
g: g,
|
||||
|
|
Loading…
Reference in a new issue