Life simulation
Category
howto
How to make a little life simulation in javascript in browser, found easy to learn repo with various life patterns by @brainxyz
This kind of code is ideal for education of javascript canvas using, its easy to understands and works in browser.
I’ve modified code a little, and achieve some stability with virus like structures which consume other particles.
Here is a gist for that code: https://gist.github.com/noroot/a3a5d4ae2d367530c8d5a0c13ca2ee75
How it works:
- There is a js canvas where all drawing is happening
- There is an atom entity which is structure of position(x,y), velocity(x,y), color
- Threr is a rule function which defines relations between particles
- There is a configuration object that defines relation between particles using rule method
- There is infinity loop of animation
- Before animation starts it creates arrays of different types of particles
References:
- https://playgameoflife.com/
- https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
- https://github.com/hunar4321/particle-life
- https://particles.js.org/
Interactive example in details below