From 09005bae0bcf710d818761a81b1484e9b54ecd5b Mon Sep 17 00:00:00 2001 From: Sooraj Sannabhadti <2005sooraj@gmail.com> Date: Wed, 14 Aug 2024 02:08:09 -0700 Subject: [PATCH] Updated background colours & default variables --- EnemyBoid.js | 4 ++-- EnemyBoidOptimised.js | 4 ++-- FriendlyBoid.js | 4 ++-- FriendlyBoidOptimised.js | 4 ++-- sketch.js | 44 ++++++++++++++++++++++------------------ 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/EnemyBoid.js b/EnemyBoid.js index 8eedfb2..2cf5427 100644 --- a/EnemyBoid.js +++ b/EnemyBoid.js @@ -154,8 +154,8 @@ class EnemyBoid { } if (direction) { - stroke(0, 0, 255); - strokeWeight(2); + stroke(255); + strokeWeight(3); line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5)); } diff --git a/EnemyBoidOptimised.js b/EnemyBoidOptimised.js index 0b83081..17e8540 100644 --- a/EnemyBoidOptimised.js +++ b/EnemyBoidOptimised.js @@ -121,8 +121,8 @@ class EnemyBoidOptimised { } if (direction) { - stroke(0, 0, 255); - strokeWeight(2); + stroke(255); + strokeWeight(3); line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5)); } diff --git a/FriendlyBoid.js b/FriendlyBoid.js index 64e79ee..6630809 100644 --- a/FriendlyBoid.js +++ b/FriendlyBoid.js @@ -167,8 +167,8 @@ class FriendlyBoid { } if (direction) { - stroke(0, 0, 255); - strokeWeight(2); + stroke(255); + strokeWeight(3); line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5)); } diff --git a/FriendlyBoidOptimised.js b/FriendlyBoidOptimised.js index 3e91021..028a6e6 100644 --- a/FriendlyBoidOptimised.js +++ b/FriendlyBoidOptimised.js @@ -128,8 +128,8 @@ class FriendlyBoidOptimised { } if (direction) { - stroke(0, 0, 255); - strokeWeight(2); + stroke(255); + strokeWeight(3); line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5)); } diff --git a/sketch.js b/sketch.js index 3a76664..3ea420b 100644 --- a/sketch.js +++ b/sketch.js @@ -19,20 +19,21 @@ if (settings_dock == 'left') { canvas_position = 0; } -let friendly_boid_count = 75; -let enemy_boid_count = 10; +// Boid variables +let friendly_boid_count = 200; +let enemy_boid_count = 3; let enemy_boid_attack_constant = 0.5; -let enemy_avoidance_constant = 0.5; -let enemy_avoidance_range = 100; -let avoidance_constant = 0.05; -let alignment_constant = 0.05; -let cohesion_constant = 0.005; +let enemy_avoidance_constant = 0.75; +let enemy_avoidance_range = 150; +let avoidance_constant = 0.15; +let alignment_constant = 0.3; +let cohesion_constant = 0.04; let interest_constant = 0.1; let poi_avoidance_constant = 0.5; let turn_constant = 0.3; let margin = 100; -let avoidance_range = 15; -let visible_range = 40; +let avoidance_range = 25; +let visible_range = 65; let poi_attraction_range = 500; let poi_protection_range = 50; let max_speed = 5; @@ -155,26 +156,29 @@ function draw() { enemy_boids.pop(); } - background(150); + background(0); + // Draw the margins + if (options[15].checked()) { + drawMargins(); + } + + // Draw points of interest + for (let poi of pointsOfInterest) { + poi.draw(protect_range = options[19].checked(), attract_range = options[17].checked()); + } + + // Draw friendly boids for (let boid of friendly_boids) { boid.update(trail = options[20].checked(), update = is_updating); boid.draw(trail = options[20].checked(), shape = options[22].value(), direction = options[21].checked(), range = options[11].checked(), avoid = options[7].checked()); } + // Draw enemy boids for (let boid of enemy_boids) { boid.update(trail = options[20].checked(), update = is_updating); boid.draw(trail = options[20].checked(), shape = options[22].value(), direction = options[21].checked(), range = options[11].checked(), avoid = options[7].checked()); } - - for (let poi of pointsOfInterest) { - poi.draw(protect_range = options[19].checked(), attract_range = options[17].checked()); - } - - // Draw the margins - if (options[15].checked()) { - drawMargins(); - } } function keyPressed() { @@ -199,7 +203,7 @@ function keyPressed() { function drawMargins() { margin = options[14].value(); - stroke(150, 0, 0, 50); + stroke(150, 0, 0, 200); strokeWeight(2); noFill(); rect(margin, margin, width - 2 * margin, height - 2 * margin);