This p5.js project, named "Asteroids," is an interactive simulation involving various entities such as asteroids, attractors, repellers, and boulders. Users can manipulate these entities using the mouse and keyboard, creating a dynamic and engaging experience.
Ensure you have a modern web browser that supports JavaScript.
- Clone the repository:
git clone https://github.com/kryturek/asteroids.git
- Navigate to the project directory:
cd asteroids/app
- Open
index.html
in your web browser to start the simulation.
Alternatively, you can view the live version of the project here.
- Attractors: Exude positive gravitational force, attracting asteroids.
- Repellers: Exude negative gravitational force, repelling asteroids.
- Boulders: Static obstacles that cause asteroids to bounce off and lose velocity.
- Asteroids: Dynamic entities that interact with attractors, repellers, and boulders. They can consume smaller asteroids when collided.
- Background: Simulated night sky with tiny, barely visible pellets moving using Perlin noise.
- Left Click: Add a new asteroid at the mouse position.
- Right Click/Backspace */: Delete entities (movers, attractors, repellers, or boulders) under the mouse cursor.
- Mouse Wheel: Change the gravitational constant
G
.
- A: Add a new attractor at the mouse position.
- R: Add a new repeller at the mouse position.
- B: Add a new boulder at the mouse position.
- C: Toggle constraint of entities within the canvas.
- P: Pause/resume the simulation.
- H: Show/hide help.
- F: Toggle fullscreen mode.
- Description: Exudes positive gravitational force, attracting asteroids.
- Behavior: Asteroids can fall into an attractor, simulating a 'black hole'.
- Description: Exudes negative gravitational force, repelling asteroids.
- Behavior: Repellers can split asteroids that have fallen into attractors, simulating a 'white hole'.
- Description: Static obstacle.
- Behavior: Asteroids bounce off boulders and lose velocity.
- Description: The only moving entity.
- Behavior:
- When collided with another asteroid, and if there's a significant difference in sizes, the bigger asteroid will 'consume' the other one, growing in size.
- Interacts with attractors, repellers, and boulders.
- p5.js: A JavaScript library that makes coding accessible for artists, designers, educators, and beginners.
If the simulation doesn't respond to inputs or behaves unexpectedly, try the following steps:
- Ensure you are using a modern, up-to-date web browser. I use Opera extensively but it doesn't seem to work well with p5.js yet.
- Check the browser console for any error messages and address them accordingly.
- Refresh the page to reset the simulation.
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.