improve object generation
This commit is contained in:
parent
b0c869b53d
commit
8ae1659fff
46
src/main.rs
46
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::<f64>(),
|
||||
vec![rand::random::<f64>(); 2],
|
||||
vec![rand::random::<f64>(); 2],
|
||||
@ -84,7 +84,21 @@ impl Object {
|
||||
)
|
||||
}
|
||||
|
||||
fn get_pos(&mut self) -> Vec<f64> {
|
||||
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<f64> {
|
||||
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<f64>> = vec![vec![0.0; 2]; objects.len()];
|
||||
|
||||
let mut events = Events::new(EventSettings::new());
|
||||
|
Loading…
Reference in New Issue
Block a user