This project implements a Reaction-Diffusion simulation using the Gray-Scott model, available in both C and web versions. It visualizes various patterns that emerge from the interaction of two virtual chemicals in a 2D grid.
Mitosis (Animated) |
Mitosis (Static) |
Coral Growth (Animated) |
Coral Pattern (Static) |
Spiral Pattern 1 |
Spiral Pattern 2 |
- Introduction
- Features
- Versions
- Mathematical Model
- Getting Started
- Usage
- Project Structure
- Building and Running
- Contributing
- Possible Improvements
- FAQ
- References
- License
Reaction-Diffusion systems are mathematical models that describe how the concentration of substances changes in space over time due to local chemical reactions and diffusion. These systems can produce a wide variety of patterns, including spots, stripes, and more complex structures, making them useful for modeling various biological and chemical phenomena.
- Real-time simulation of the Reaction-Diffusion process
- Multiple pre-defined patterns (see Changing Patterns)
- Interactive controls (see Controls)
- Cross-platform support (C and Web versions)
- Easy-to-use build system
The C version provides a decent-performance simulation using the Raylib graphics library. It offers:
- Decently fast, real-time rendering
- Platform-native window and controls
- Easy compilation and execution via batch file
Jump to C installation instructions
The web version allows for easy access and sharing of the simulation. Features include:
- Browser-based simulation (no installation required)
- Interactive UI for pattern selection and parameter adjustment
- Responsive design for various screen sizes
This simulation uses the Gray-Scott model, defined by the following partial differential equations:
∂A/∂t = D_A ∇²A - AB² + f(1-A)
∂B/∂t = D_B ∇²B + AB² - (k+f)B
Where:
- A and B are the concentrations of two chemicals
- D_A and D_B are the diffusion rates of A and B
- f is the feed rate
- k is the kill rate
- ∇² is the Laplace operator
- For C version:
- C compiler
- Raylib graphics library
- For Web version:
- Modern web browser with JavaScript enabled
-
Clone the repository:
git clone https://github.com/datavorous/Gray-Scott-Reaction-Diffusion-Model.git
-
For C version, install Raylib following the instructions on their website.
-
The web version requires no additional installation.
Navigate and run the build.bat
file, after placing the libraylib.a
file inside the lib/
folder. This will compile and run the simulation.
Open the index.html
file in your web browser, or visit the online demo.
- Left-click: Add chemical B to the simulation
- Spacebar: Pause/unpause the simulation
- Enter key: Reset the grid
To change patterns in the C version, modify the f
and k
values in the main.cpp
file according to this table:
Pattern | f | k |
---|---|---|
Mitosis | 0.0367 | 0.0649 |
Coral Growth | 0.0545 | 0.062 |
Fingerprint | 0.055 | 0.062 |
... (and so on) |
In the web version, use the dropdown menu to select different patterns.
reaction-diffusion-simulation/
├── bin/
│ └── Makefile
├── include/
├── lib/
├── src/
│ └── main.cpp
├── build.bat
├── index.html
└── README.md
- Navigate to the
bin
folder - Double-click
build.bat
or run it from the command line - The script will compile the code and launch the simulation
We welcome contributions to the Reaction-Diffusion Simulation project! Here's how you can help:
- Fork the repo and create your branch from
main
. - Make your changes, adhering to the best practises.
- Ensure your code passes all tests.
- Submit a pull request.
- Check existing issues before creating a new one.
- Provide detailed information: version, OS, steps to reproduce, expected vs. actual behavior.
- Use the accepted and standard procedure for a given language.
- Use 4 spaces for indentation.
- Write clear, well-commented code.
Follow the Conventional Commits specification:
type(scope): brief description
Longer description if necessary
Closes #123
- Write unit tests for new features or bug fixes.
- Ensure all tests pass before submitting a PR.
- Update README.md and comments for significant changes.
- Implement real-time parameter adjustment in C version
- Add option to switch between different models
- More liquids?
- Optimize for larger grids using GPU acceleration
- Implement more complex reaction-diffusion systems
Q: Why does the simulation slow down with larger grids? A: The computational complexity increases with grid size. Consider lowering the resolution or using a more powerful machine.
- Pearson, J. E. (1993). Complex Patterns in a Simple System. Science, 261(5118), 189-192.
- Turing, A. M. (1952). The Chemical Basis of Morphogenesis. Philosophical Transactions of the Royal Society B, 237(641), 37-72.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Note: This project is for educational purposes only. It does not claim to accurately represent real-world chemical or biological processes.