This project simulates fungal growth using a grid-based visualization and generates an animated GIF of the simulation.
fungalLife.js
: The main JavaScript file that contains the code for the fungal growth simulation.
-
Install Dependencies: Ensure you have Node.js installed. Then, install the required npm packages:
npm install canvas gifencoder
-
Run the Simulation: Execute the following command to run the simulation and generate the GIF:
node fungalLife.js
- The simulation uses a 200x200 grid.
- Each cell can be in one of the following states:
EMPTY
: Represented by 0.HYPHAE
: Represented by 1.TIP
: Represented by 2.SPORE
: Represented by 3.
- The grid is initialized with one spore placed at the center of the grid.
- Spores can turn into tips with a probability of 0.1.
- Tips grow into hyphae and can create new tips in one of the eight possible directions (including diagonals).
- Hyphae can randomly turn into spores with a probability of 0.01.
- The grid is visualized using the
canvas
library. - Different cell states are represented by different colors:
EMPTY
: WhiteHYPHAE
: GreenTIP
: Dark GreenSPORE
: Brown
- The simulation is captured and saved as an animated GIF using the
gifencoder
library. - The GIF is created with a delay of 100 ms between frames and a quality setting of 10.
- The
simulate
function runs the simulation for 1000 iterations and generates the GIF.
- The output GIF file will be saved as
fungal-life.gif
in the project directory.
To run the simulation, use:
node fungalLife.js
- Modify the grid size, cell size, and probabilities in the code as needed for different simulation behaviors.
- Ensure the required libraries are installed before running the script.