Skip to content

fglo/particles-rules-of-attraction

Repository files navigation

Go Build Deploy Webasm

Particles' Rules of Attraction Simulator

Program simulating particles' rules of attraction.

It's heavily inspired by hunar4321's life_code (it started as a port of his javascript code).

https://evolution.berkeley.edu/the-history-of-evolutionary-thought/1900-to-present/endosymbiosis-lynn-margulis/ https://www.ventrella.com/Clusters/

Gif

500 particles of each color:

gif

1000 particles of each color:

gif3

Different amounts of each color of particles:

  • 100 red particles
  • 1500 green particles
  • 500 blue particles
  • 1200 yellow particles

gif4

Other random results:

gif5

gif6

Roadmap (if I have time and energy to put into it)

  • User Interface: changing rules live
  • User Interface: adding/removing new types (colors) of particles
  • User Interface: rules import/export
  • computation parallelization
  • rule mutations
  • optimalizations :v (always ongoing)

Running simulation

Desktop

Run the program using go run command:

go run cmd/particlelifesim/main.go

Web

simulation visualization (bad performance tho)

Compile the program to webasm and run a http server:

GOOS=js GOARCH=wasm go build -o static/main.wasm cmd/particlelifesim/main.go
python3 -m http.server --cgi 8080 --directory static/ 

or run the program using wasmserve

go install github.com/hajimehoshi/wasmserve@latest
wasmserve ./cmd/particlelifesim/