# Gas Universe Simulator

Discussion in 'Tools for Investigating and Debunking' started by Mick West, Nov 1, 2018.

Tags:

It's a fun little toy. One interesting thing was when using gasGravity, and the settings shown, then the blob of molecules would rotate, almost seeming to form spiral arms at one point.

On my Mac it works best on Safari, then on Firefox, and is slowest (by far) on Chrome.

4. ### MauroNew Member

A great fun little toy Which language did you use to write it?

Javascript, which isn't optimal of course, but is easiest to share. And it does 20,000 particles at 60 fps in Safari on my Mac, which is quite astounding.

Just added a "Pause" button, which lets you set things up better

6. ### Dan LyNew Member

Nice simulation Mick! I gave a quick glance at your code to see what you did. From what I understand you created a grid and calculated collisions/ gravity between particles found only in the same partition is that correct? I have created my own N-body code but it's a direct particle-particle method which is accurate but slow for a large number of particles (I use it to simulation the solar system). I'd like to try something on this scale sometime using a space partitioning method like this.

Only for the collisions, and it checks for collisions in the same partition (cell) and in the up, down, left, and right cells. It does not check diagonal cells, so occasionally misses a few (leading to temporary overlaps). It also only does a simple radius overlap check for collisions, so will also miss quite a few at higher speeds (not leading to overlaps). However that's acceptable for simulating gasses, as the individual collision are not each important, just that you get a bunch of them.

For gravity it does the full N*N calculations, which is why it's slow with lots of particles. The math is simpler though.

Hah, just spotted a bug:
Code:
```if (d2>0) {
var d = Math.sqrt(d2);
dx /= d;
dy /= d;
var a = g / d2;
p.vx += dx * g;
p.vy += dy * g;
}
```
I thought the gas gravity was a bit boring, fix to come.

Gas gravity patched.
https://www.metabunk.org/gas/

Now forms local clusters as you expect, so you can kind of use it to simulate galaxy formation!