Show HN: Life Simulation Written in Rust

Author: joelthelion

Score: 168

Comments: 31

Date: 2021-11-28 15:57:23

Web Link

________________________________________________________________________________

joelthelion wrote at 2021-11-28 15:57:30:

I made this simple 2D simulation of life using Rust. I find it fascinating to see how complex patterns can emerge from simple rules, and how well natural selection works!

The code is not extremely pretty, but I'm happy with the results. I'm quite amazed that I was able to port the whole thing to the web with very little effort!

jacobmischka wrote at 2021-11-28 17:21:13:

Macroquad is great, it does make that virtually effortless. Nice work!

ASalazarMX wrote at 2021-11-29 20:37:40:

I had to close the tab because I know I will stare at it for a while and I'm at work. Really interesting.

Is the "biot" name a reference to Rendezvous with Rama?

SkyMarshal wrote at 2021-11-28 19:02:29:

Question - it seems you explained what all the colors do, but what do the different shapes mean (squares and circles)?

alexeldeib wrote at 2021-11-28 19:05:34:

Square indicates intelligence, which allows them to move non randomly towards the nearest edible biot (it’s on the page right after the bullet points).

artursapek wrote at 2021-11-28 18:46:40:

This is awesome, thanks for sharing. I may tinker with it

woodruffw wrote at 2021-11-28 19:07:24:

This is extremely cool! I wonder how much work it would be to bundle it up into an XScreenSaver-compatible binary.

Edit: It looks like running it locally on X11 is trivial, so this should be easy to do. I'm trying to hack it together now :-)

Datagenerator wrote at 2021-11-28 22:01:09:

That would be great. Another awesome screensaver is called substrate and included in the set 1) by Jamie Zawinski ( among the founders of Netscape and Mozilla ).

1)

https://www.jwz.org/xscreensaver/

phyalow wrote at 2021-11-28 22:28:25:

Anyone else getting an edgy anti ddos message?

woodruffw wrote at 2021-11-28 22:32:18:

You can avoid that by not sending a Referer header with your request.

jwz's default redirect for HN is well known[1] (and, IMO, apt).

[1]:

https://news.ycombinator.com/item?id=25801699

joelthelion2 wrote at 2021-11-28 19:17:44:

That would be awesome :)

woodruffw wrote at 2021-11-28 19:40:13:

Looks like it won't work out of the box, unfortunately, since {macro,mini}quad doesn't support a custom X11 parent window :-(

But I've opened an issue upstream to track functionality in the renderer that would allow this[1].

[1]:

https://github.com/not-fl3/miniquad/issues/250

krisrm wrote at 2021-11-28 16:43:16:

This is neat! The simulation didn't remain "stable" for me for very long though; biot count pushed over 3000 and I dropped to just a few fps. I'm on a phone and I'm also a bit color blind so I'm probably not the ideal use case.

joelthelion wrote at 2021-11-28 16:49:29:

If you wait for a few more minutes, it's highly likely that a predator will emerge. Maybe you were just unlucky though.

Ardon wrote at 2021-11-28 18:50:04:

I made it to 8500 before an effective predator evolved. Glad I waited, it was neat.

bschwindHN wrote at 2021-11-28 23:48:25:

Much more interesting than Conway's game of life! Thanks for sharing.

worldmerge wrote at 2021-11-28 22:23:09:

That looks really cool! What graphics library did you use or did you make your own?

Also how did you compile rust code for the web? And were there any challenges with it like weird browser issues?

jacobmischka wrote at 2021-11-29 01:02:25:

Answer to both questions:

https://macroquad.rs/

lloydatkinson wrote at 2021-11-28 21:52:49:

Could you add some keyboard shortcuts to make it skip a few dozen generations?

nynx wrote at 2021-11-28 17:10:03:

Awesome! Now you gotta port it to wgpu and run the simulation on the GPU!

joelthelion2 wrote at 2021-11-28 18:39:40:

I would love to learn how to do that!

I'm not certain it would improve things, though, as the most time-consuming step is computing interactions between biots.

nynx wrote at 2021-11-28 19:05:44:

Yeah, by computing on the gpu (or by using a spatial partitioning system like a quad-tree), you could probably speed that up massively.

nynx wrote at 2021-11-28 20:25:27:

Oops, you're already using a R* tree!

joelthelion wrote at 2021-11-28 21:19:39:

:-)

la_fayette wrote at 2021-11-28 21:10:50:

Is this a specific algorithm, defined like conways game of life? I have never read any Rust source code, so I would like to unterstand it generally...

joelthelion wrote at 2021-11-28 21:31:42:

This is closer to real life than Conway's algorithm. Biots are able to move freely, have a very simple genome that gives them unique characteristics, and natural selection does the rest. There is a succinct description of the rules at the bottom of the demo page.

cosmodisk wrote at 2021-11-28 18:33:57:

This is super nice: I sat for nearly 10 min observing how the numbers go up and dow and how they consume each other.

8589934591 wrote at 2021-11-29 06:45:05:

Neat. Is there a way I can use this as a screensaver on linux?

joelthelion wrote at 2021-11-29 18:23:39:

Check woodruffw's comment above. He's trying to do just that :)

syspec wrote at 2021-11-28 18:29:43:

Because it is written in Rust, this is the most secure life simulation to exist.

joelthelion2 wrote at 2021-11-28 18:38:38:

Believe it or not, there is an annoying bug in the R* tree crate I use that causes it to occasionally panic. I added a very ugly workaround that seems to work quite well though :)