Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed issue with visible range not showing
Browse files Browse the repository at this point in the history
- Added license and creator info to the README file.
- Fixed the issue with visible range not being drawn when box is checked.
  • Loading branch information
WhenLifeHandsYouLemons committed Aug 28, 2024
1 parent 73369fc commit 7d4922e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions EnemyBoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,11 @@ class EnemyBoid {
strokeWeight(3);
line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5));
}

drawVisibleRange() {
noFill();
stroke(0, 255, 0, 50);
strokeWeight(2);
ellipse(this.position.x, this.position.y, visible_range * 2);
}
}
7 changes: 7 additions & 0 deletions EnemyBoidOptimised.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ class EnemyBoidOptimised {
strokeWeight(3);
line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5));
}

drawVisibleRange() {
noFill();
stroke(0, 255, 0, 50);
strokeWeight(2);
ellipse(this.position.x, this.position.y, visible_range * 2);
}
}
7 changes: 7 additions & 0 deletions FriendlyBoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,11 @@ class FriendlyBoid {
strokeWeight(3);
line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5));
}

drawVisibleRange() {
noFill();
stroke(0, 255, 0, 50);
strokeWeight(2);
ellipse(this.position.x, this.position.y, visible_range * 2);
}
}
7 changes: 7 additions & 0 deletions FriendlyBoidOptimised.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,11 @@ class FriendlyBoidOptimised {
strokeWeight(3);
line(this.position.x, this.position.y, this.position.x + (this.velocity.x * 5), this.position.y + (this.velocity.y * 5));
}

drawVisibleRange() {
noFill();
stroke(0, 255, 0, 50);
strokeWeight(2);
ellipse(this.position.x, this.position.y, visible_range * 2);
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ The visible range is the radius around each boid that it can see other boids. If
## Extras

This could be expanded on even more by adding more rules or changing the existing rules. For example, we could add a rule for boids to follow a path. We could also add an extra dimension and make the simulation work in 3D! The possibilities are endless!

---

This project is licensed under the MIT License. You can find a copy of the license in the [LICENSE](LICENSE) file.

Created and hosted by [Sooraj](https://sooraj.dev/).
11 changes: 11 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ function draw() {
boid.drawAvoidanceRange();
}
}

// Draw visible ranges
if (options[11].checked()) {
for (let boid of friendly_boids) {
boid.drawVisibleRange();
}

for (let boid of enemy_boids) {
boid.drawVisibleRange();
}
}
}

function keyPressed() {
Expand Down

0 comments on commit 7d4922e

Please sign in to comment.