Added vectors indicators

This commit is contained in:
2022-05-11 13:04:20 +02:00
parent e27180a4b3
commit dd49731ea8

View File

@@ -20,10 +20,10 @@ const WINDOW_HEIGHT:i32 = 600;
const WINDOW_WIDTH:i32 = 800;
const BIRD_SPEED:i32 = 2;
const MAX_BIRD_SPEED:i32 = 15;
const BIRDS_COUNT:i32 = 500;
const BIRDS_COUNT:i32 = 200;
const BIRD_SIZE:i32 = 15;
const VISION_RANGE:i32 = 150;
const VISION_RANGE:i32 = 100;
const COHERENCE_RATE:i32 = 1;
const SEPRATION_RATE:i32 = 1;
const ALIGNEMENT_RATE:i32 = 1;
@@ -41,9 +41,14 @@ impl Simulation{
pub fn render(&mut self,ctx:&mut sdl2::render::Canvas<sdl2::video::Window>){
ctx.set_draw_color(Color::RGB(0x6D, 0x6D, 0x64));
ctx.clear();
ctx.set_draw_color(Color::RGB(0x33, 0x33, 0x33));
for bird in self.birds.iter(){
ctx.set_draw_color(Color::RGB(0x33, 0x33, 0x33));
ctx.fill_rect(bird.shape).expect("Rusty Boids");
ctx.set_draw_color(Color::RGB(0xe7, 0x4c, 0x3c));
let start_pos = Point::new(bird.shape.x + bird.shape.width() as i32 / 2,bird.shape.y + bird.shape.height() as i32 /2);
let end_pos = Point::new(start_pos.x + bird.velocity.x * 2,start_pos.y + bird.velocity.y * 2);
ctx.draw_line(start_pos,end_pos).expect("Could nor draw vector line");
}
}
pub fn apply_coherence(&mut self){
@@ -231,8 +236,8 @@ impl Simulation{
}
posx += bird.velocity.x;
posy += bird.velocity.y;
posx += bird.velocity.x / 2;
posy += bird.velocity.y / 2;
bird.shape.set_x(posx);
bird.shape.set_y(posy);
}