stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

Particle Evolution

  • 7 Devlogs
  • 21 Total hours

A genome based Particle Life simulation

Ship #1

Project is available for download on Windows and Linux

I made a particle simulator with genomes. Inspired by Particle Life, the particles interact with each other through attraction and repulsion which when millions of times across thousands of particles creates really cool patterns. The particles also have DNA as explained in the README

This was a lot of fun, I find emergent behaviours really cool, and even though I wasn’t able to accomplish everything I wanted to do I’m still happy with how it turned out. I also learned a lot about how GPUs work which is becoming very relevant very fast.

This might be my last Stardance project so I just want to say thank you to all the Hack Club staff for running this, and all the other Stardancers for making it what it is. I had a great summer and I hope you all did too :>

  • 7 devlogs
  • 21h
  • 14.66x multiplier
  • 314 Stardust
Try project → See source code →
Open comments for this post

1h 1m 34s logged

Devlog 4

Last one before I ship! I finalised a few things before release, mostly just messed with the UI. This project was also really hard to package because of the way Taichi compiles code. Long story short before it compiles it check to see if what you’re doing is legal, and for that it has to read the actual source code. When you package a project with something like PyInstaller, the source code gets lost which breaks Taichi. The fix for this was to include a copy of the physics code in plaintext within the executable, so Taichi had something to look at. Shout out to Claude for helping me fix that, I probably never would have figured that out on my own.

Anyway that’s it

0
0
27
Open comments for this post

7h 12m 18s logged

Devlog 3

It’s been a long time! After a lot of procrastinating and trial and error, and banging my head against the wall trying to figure out evolution, I decided to pivot. I kept the genome system, but scrapped the evolution in favour of manual tuning

Genomes

I went over this in the last devlog but I’ll mention it again cause it’s important and it’s changed a little. The current system works with a fixed number of species, each with a unique genome. A genome is made of 3 traits (0 to 1) and 3 receptors (-1 to 1) and each receptor interacts with it’s respective trait on a neighbouring particle. For example, if Trait 1 on Particle A is 1, and Receptor 2 on Particle B is also 1, B will be attracted to A. Likewise, if Receptor 1 on Particle B is -1, B will be repelled by A

Rendering

Aside from solidifying the genome system, the biggest change from the last update is a full shift to GPU rendering. The previous version used Pygame to draw the window, but now I’m using Taichi’s UI library. The benefits of this are that information is no longer being sent between the CPU and GPU, significantly increasing speed. Also, the rendering itself is parallelized, making it even faster.

Other Changes

I added detailed controls for changing population, species count, genomes, visuals and more. I also added a system to save and load configurations.

Next?

I’m gonna leave this project for a bit, but I might come back to it in the future. If I do, I want to find some way to turn it into a live wallpaper / screensaver.

It’s like the moon!

0
0
14
Open comments for this post

1h 36m 17s logged

Devlog 2.5 - Chaos

Really small update! I starting implementing the evolution, it’s very very simple right now but I just wanted to share this cause I think it looks cool. I won’t go into too much detail here but basically instead of a fixed species/color each particle has a genome. The genome is made of traits, and receptors (attraction/repulsion to certain traits). When particles get close to each other, they share a bit of DNA. I’ll probably change the evolution mechanism very soon because I don’t think this method is really viable but it’s a start :>

0
0
14
Open comments for this post

3h 32m 10s logged

Devlog 2 - Organisms

I finally got around to adding GPU integration. I can now comfortably run 20,000+ particles, before I was capped at around 1,500.

There’s no other additions so I’m gonna talk about the implementation for a bit. I used a really cool module called Taichi. It basically lets you put a little tag above functions to tell them to compile into GPU code. For it to work you have to convert whatever you’re doing to use different datatypes since the GPU doesn’t understand python types. Regular numbers are the same but I struggled a good but trying to understand Vectors and Fields. I think a field is like a space that contains data, in 1, 2, or 3 dimensions. A vector is roughly equivalent to a list in Python. The part that confused me was putting vectors in fields, and the difference between vector dimensions and field dimensions.

To actually implement Taichi I pretty much had to rewrite the whole backend, but thankfully the actual equations stayed mostly the same it was just the structure. Previously I had a big list of Particle objects with their own functions handling their own physics. Now particles are purely numerical, there’s just a big list of positions and a big list of colors used to render them.

It was pretty interesting learning how to use Taichi, I’ll probably integrate it into future projects. or experiment with the GPU in other languages. As for this project, I called it Particle Evolution but I still haven’t fully figured out how I want the evolution to function. Hopefully I’ll have something next devlog :>

30,000 particles!

0
0
8
Open comments for this post

1h 7m 12s logged

Devlog 1.5 - Life

Another small update. I still wasn’t completely happy with the physics after my last devlog so I looked at the code of another particle life simulation and realised I was doing some of the calculations wrong. It turns out I never fully fixed the strong repulsion equation, also I was applying the friction in the wrong order. Aside from bug fixes, I incorporated delta (the real time since the last frame) into all the calculations to account for framerate fluctuations.

I’m now pretty happy with the way the particles interact, and I think I can start translating the code to run on the GPU - hopefully I don’t need to rewrite too much of it

0
0
9
Open comments for this post

3h 21m 31s logged

Devlog 1 - Cells

Quick update to my Particle Life project. I did some work to stabilise the physics, there were a lot of small mistakes in the code that added up to very erratic behaviours. For example, the repulsion force that’s supposed to stop the particles from overlapping too much was partially inverted and actually made things worse. I’m starting to get better results now but it’ sstill not perfect.

I also added a little grid to visualise the relationships between different ‘species’. I’m still relatively new to Pygame so it was interesting trying to get the dragging and clicking working

The last change is less noticeable but I did some light optimization. I basically added an invisible grid, so instead of checking the distance to every particle every frame, each particle only looks at neighbouring cells. It’s an improvement, but there’s still a long way to go as far as optimization. Hopefully I can figure out how to get it to run on the GPU soon

0
0
11
Open comments for this post

3h 32m 31s logged

Devlog 0 - Primordial Soup

I started making my Particle Life simulation. I got the basic features working, but it’s very unoptimised. Every particle checks every other particle every frame, and it’s all done using the CPU. I’ll elaborate more on how I’m going to solve this in the future.

For anyone who doesn’t know, Particle Life works by simulating attraction and repulsion forces between different kinds of particles. For example, here you can see that blue is attracted to itself, causing it to form big clumps. You can also see that blue is attracted to green, but green repels blue, effectively making blue chase green around really fast.

What’s Next?

The two things I plan on doing next are optimisation, and customisation. I’m not sure which will come first, but hopefully by the time I finish I’ll know how I want to implement the evolution

0
0
11

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…