I've had this idea kicking around in my head for years. The gist of it was "what if I made a simulation of gravity using cellular automata". Well, I finally got around to doing so. I'll give some technical details after, but here are some images of what came about:

This shows two fields blending together.

A heart-shaped block of mass causing interference patterns with itself.

Four "black holes" that developed.

Ended up fixing the blending of colors to get better spectrums.

It's just neat!

This inspires terrain generation.

The next few are just pretty:

Here are a few videos of it in action:

Technical details:
Mass and gravity are modeled as two 2D fields. The user inputs mass particles with a given mass, determined by the Divisor input (MaxMass / Divisor). As the simulation runs, it updates the gravity and mass fields based on each other. The mass field is conserved, meaning no particles will ever "disappear". The gravity field is calculated from the mass field and itself.

For each gravity cell, it looks at the mass field, and sets the gravity to MassValue shifted right by 3. It then takes the average of the gravity from all adjacent cells, and adds that to the current gravity from the mass field.

For each mass cell, it looks at the adjacent gravity field cells as well as its own gravitation field cell. It orders them by strength, and randomly picks the strongest gravitation to "fall" towards. This could mean "falling" toward its own cell, thus not moving. If a cell (other than itself) occupies the cell it tries to fall toward, it falls toward another random cell with the same gravitation strength. If all cells with the highest gravitational strength are occupied, it goes to the next strongest gravitational strength. It does this until there are no other cells, in which case it stays put.

You can find the code to this, and incidentally lots of other little toys I've made over the years, in my github: https://github.com/merthsoft/MooseLib/tree/master/GravityCa

Requires .net 8, should run anywhere with a .net 8 runtime (Windows, Mac, many Linuxes).

Controls:
Space - toggles simulation running or paused
Left click to add a mass with the current divisor
Right click to remove mass
0 - Grayscale palette
1 - Rainbow palette
2- Two rainbows
3 - Three rainbows
4 - Four rainbows
5 - Six rainbows
6 - Eight rainbows
7 - Twelve rainbows
8 - Sixteen rainbows
9 - I dunno like sixhundred rainbows or somthing like that

1 through 0 on the number ROW (not numpad) will change the number of values used to render the gravity.

T - Draw debug text
M - Toggle mass renderer
G - Toggle gravity renderer
B - Toggle blending the colors between values

Z - Zero-out mass field
X - Zero-out gravity field
R - Randomly fill .01% of the remaining open mass field with the current divisor
F - Fill the mass field with the current divisor

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum