diff --git a/src/main.rs b/src/main.rs index 726334b..0234d91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,9 +73,9 @@ impl Object { } } - pub fn new_rand(color: [f32; 4]) -> Object { + pub fn new_rand() -> Object { Object::new( - color, + [1.0, 1.0, 0.0, 0.8], rand::random::(), vec![rand::random::(); 2], vec![rand::random::(); 2], @@ -84,7 +84,21 @@ impl Object { ) } - fn get_pos(&mut self) -> Vec { + fn randomize_color(&mut self) { + const RED: [f32; 4] = [1.0, 0.0, 0.0, 0.8]; + const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; + + const FRUNK: [f32; 4] = [0.0, 0.0, 1.0, 0.8]; + const GNORM: [f32; 4] = [1.0, 1.0, 0.0, 0.8]; + + const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 0.8]; + + let colors = [RED, FRUNK, GNORM, WHITE, GREEN]; + self.color = *colors.choose(&mut rand::thread_rng()) + .expect("Color failure!"); + } + + fn get_pos(&self) -> Vec { self.pos.clone() } @@ -222,19 +236,10 @@ fn main() { println!("Hello there!"); let mut m_attract = false; - const RED: [f32; 4] = [1.0, 0.0, 0.0, 0.8]; - const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; - - const FRUNK: [f32; 4] = [0.0, 0.0, 1.0, 0.8]; - const GNORM: [f32; 4] = [1.0, 1.0, 0.0, 0.8]; - - const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 0.8]; - - let colors = [RED, FRUNK, GNORM, WHITE, GREEN]; - let opengl = OpenGL::V3_2; - let num_objs = 512; + const NUM_OBJECTS: usize = 512; + dbg!(NUM_OBJECTS); let mut window: Window = WindowSettings::new("Test", [200, 200]) .opengl(opengl) @@ -246,14 +251,11 @@ fn main() { gl: GlGraphics::new(opengl), }; - let mut objects = Vec::new(); - for _ in 0..num_objs { - objects.push(Object::new_rand( - *colors - .choose(&mut rand::thread_rng()) - .expect("Color failure!"), - )) - } + let mut objects = vec![ + Object::new_rand(); + NUM_OBJECTS + ]; + objects.iter_mut().for_each(|obj| obj.randomize_color()); let mut positions: Vec> = vec![vec![0.0; 2]; objects.len()]; let mut events = Events::new(EventSettings::new());