I made Artificial Life.
I made Artificial Life.
So, recently I have been dumbstruck by the idea of artificially created life forms. No, these are not biological life forms as you might think. These are more like simulations that act like organisms due to there environment and set of rules in that environments.
Lets get started. So in my dive in this topic I realised to start this topic one of the most basic way to simulate life is “Conway’s Game of Life”.
What this idea basically says is there are three rules in the world of this concept:
- Any live cell with two or three live neighbours survives.
- Any dead cell with three live neighbours becomes a live cell.
- All other live cells die in the next generation. Similarly, all other dead cells stay dead.
All cells follow this 3 rules and then they are simulated.
There are many organisms that are observed in this. Some of them are the following:
So, Lets get to coding this thing:
Firstly lets get all the necessary imports out of the way:
After that lets add some prerequisites and initialise the pygame env:
Now lets make a draw grid funtion to draw the grid:
When we exicute the above funtion it should look like this:
Lets code a random function to generate random positions for the initial cells:
Lets now code a adjust grid function:
Now we need to check how many neighbours are around each of the cells according to which we will reproduce or kill cells which can be done via the following function:
Now lets bring everything together using the main() funtion. It will pause and play the simulation using the <tab> key and generate random cells using the <g> key. It will also add and delete cells based on where the mouse clicks in the grid.
After this is done lets run the main function:
Now our code is done!! we can simulate life now.
Lets see some outputs:
So, in the output above we generated random cells in random postions we can observe many organisms based on the above chart given in the article.
So, this article will be followed soon by the implementation of Lenia: Artificial Life forms so stay tuneedd for that.
Here is a spoiler:
If you like the article a follow would help me alot.
Thanks alot for reading my weird nerd stuff.
I appreciate you guys alot.
For the code go here:
Contribute to Eeman1113/Artificial_Life development by creating an account on GitHub.github.com
For More About Me Go Here:
https://www.linkedin.com/in/eeman-majumder-2184331a2/
Thanks for reading 😁, See ya guys very soon👋🏼