Skip to content

Commit

Permalink
Make the bodies' size proportional to their mass
Browse files Browse the repository at this point in the history
  • Loading branch information
sulami committed Apr 17, 2024
1 parent a388863 commit a32eda9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Binary file modified docs/three-bodies.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn main() {
fn has_collision(bodies: &[Body]) -> bool {
for i in 0..bodies.len() {
for j in i + 1..bodies.len() {
if bodies[i].position.distance(bodies[j].position) < 10.0 {
if bodies[i].position.distance(bodies[j].position) <= bodies[i].mass + bodies[j].mass {
return true;
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ impl Body {

/// Draws the body on the screen.
fn draw(&self) {
draw_circle(self.position.x, self.position.y, 5.0, self.colour);
draw_circle(self.position.x, self.position.y, self.mass, self.colour);
}

/// Updates the velocity of the body based on the forces applied by other bodies.
Expand Down

0 comments on commit a32eda9

Please sign in to comment.