7 ms·
Show HN: Genetic Boids Web Simulation
- isoprophlex 1y agoI'll just say that this looks insanely good, wow.
- vimgrinder 1y agothanks!
- kldavis4 1y agohow are genetic (algorithms) used?
- vimgrinder 1y agoso, i just used them like conceptually.. each boid has a string, when boids come close , they produce a offspring with mixed string + mutation age lets boids die too nothing fancy, just for sake of sim
- knome 1y agoI was playing around, and inspected the boid count control to see if I might manually update it and see what unreasonably large and small populations look like. I saw the connected callback triggered updateProperty. Running updateProperty("boidCount", 10) in the console yielded a field with 10 boids, as expected, but apparently it doesn't update something else the natural code would, as as soon as two of the boids collided, a humongous explosion of boids occurred, like a firework.
- deleted 1y ago[deleted]
- chipsrafferty 1y agoanything AI can do GAs can do worse
- brulard 1y agoThat's beautiful. What are "signals"?
- Xevion 1y agoI don't know myself, but it seems to give boids their own unique state and add another layer of influence to their acceleration. https://github.com/attentionmech/genetic-boids/blob/485fe482885c4a6850b73e1954609024297b1c1a/index.html#L389-L421 https://github.com/attentionmech/genetic-boids/blob/485fe482... I'm reading the code but I don't know what it actually DOES in practice; my guess is that Boids with opposite genomes (binary strings with default length 6) are slightly attracted to eachother.
- deleted 1y ago[deleted]
- vimgrinder 1y agoyes this only.
- rvnx 1y agoNever heard of such thing, love it!
- Xevion 1y agoI learned about Boids when I was 16 thanks to Sebastian Lague's amazing video on it: https://youtu.be/bqtqltqcQhw https://youtu.be/bqtqltqcQhw Highly recommend, especially his older videos on simulations.
- mewse-hn 1y ago[flagged]
- deleted 1y ago[deleted]
- vimgrinder 1y agofixed it. lowered the values and clipped.
- rriley 1y ago[flagged]
- 9dev 1y agoIf you got insights from that response, why not talk about those instead of copy-pasting a wall of shallow LLM output here?
- rriley 1y agoThanks for the feedback and sorry for the lengthy post. These insights were actually quite useful for me to understand what these "genetic boids" are. I thought others might find them useful too. Lesson learned for the next time ^_^
- vladde 1y agoReminds me of this similar thing!, creating life like behavior with only simple rules https://youtu.be/0Kx4Y9TVMGg?t=40 https://youtu.be/0Kx4Y9TVMGg?t=40 (the coolest examples come at about half a minute into the video)
- Xevion 1y agoAwesome work, the green terminal style is really cool. And the fact that it's just Vanilla JavaScript, HTML & CSS is a pretty cool touch. I would've produced something a tenth the style with 10x the complexity Just some ideas/suggestions: - Better colors: maybe genes can influence colors a bit? The random colors aren't that great, they're good though for making all the boids distinct. - Zooming: Scroll the mousewheel to Zoom In/Out, drag to move around - Interactive: Click on a Boid, have it be followed around using zoom! - Time controls: Not just framerate, but a % multiplier on simulation speed. - GPU Refactor: I don't think you're doing any of this yet, so maybe optimizing for a GPU-based speedup would be cool? See if you can reach 10,000 boids! Sebastian Lague's video goes into parallelization, just not in JavaScript: https://youtu.be/bqtqltqcQhw https://youtu.be/bqtqltqcQhw
- vimgrinder 1y agohey thanks! color is coming from genome (check brightColorFromGenome)! nice suggestions, will definitely try to incorporate some of them.
- talkingtab 1y agoThe original Boids is from Craig Reynolds, here: https://www.red3d.com/cwr/boids/ https://www.red3d.com/cwr/boids/ It was a java applet (sigh) and unfortunately I have not been able to find a working version. That version based on his three "steering" mechanisms had very realistic movement. Other versions, including this one, which are good do not have that same kind of quality. They look like simulations whereas the Reynolds version, for whatever reason, seemed much closer to watching an actual flock. No criticism intended, it would just be nice to understand the why the difference. Looking briefly at the code, it seems the fitness function is simply how close the boids are? Very cool!
- vimgrinder 1y agooh, so i wasn't really aware that there was a original boid sim (I will check it today). mostly I saw it on some other demos and I wanted to add this behaviour of signaling boids which are far away + color code based on genome + do a simple cross-mutate. and yes you are right about fitness func. Beyond this i was trying to add a map which effects their movement. (if you wanna check how it looks - https://x.com/attentionmech/status/1925690991555531143 https://x.com/attentionmech/status/1925690991555531143)
- janzer 1y agoJust a clarifying note, Craig Reynolds is the original researcher for Boids, and he did have a Java applet implementation in the above page. But the original Boids simulation was from 1986, almost a decade prior to Java applets. The original paper, published in 1987, is "Flocks, herds and schools: A distributed behavioral model"[1]. The implementation was done in Lisp on a Symbolics 3600 Lisp Machine. Edit: One quite interesting paragraph from the paper regarding performance: The boid software has not been optimized for speed. But this report would be incomplete without a rough estimate of the actual performance of the system. With a flock of 80 boids, using the naive O(N²) algorithm (and so 6400 individual boid-to-boid comparisons), on a single Lisp Machine without any special hardware accelerators, the simulation ran for about 95 seconds per frame. A ten-second (300 frame) motion test took about eight hours of real time to produce. Once again, amazing how far hardware has advanced. 1. https://dl.acm.org/doi/10.1145/37402.37406 https://dl.acm.org/doi/10.1145/37402.37406
- deleted 1y ago[deleted]
- brodo 1y agoI've just built a boid simulation in Go and WebGPU. 16k boids are no problem on my M1 Mac Pro. I did not implement any optimization yet.
- vimgrinder 1y agooh nice, webGPU thing should learn sometime!
- anigbrowl 1y agoI really like it, though I'm finding it dies consistently after about 30s (Vivaldi on an intel iMac with a decent GPU).
- vimgrinder 1y agodies in the sense machine gets hung or all boids vanish? EDIT: also pushed some fixes in params (allow offsprings at larger distance, etc), but basically if the boids don't end up closer, they won't reproduce and the population dies so play with that and lmk
- diggan 1y agoNoticed that all the boids lifetime seems to be the same, so you go from "a flock" to "nothing" very quickly if the lifetime been hit. What I've done before with "crowd simulations" like these, is add another params, something like "random lifetime interval" where if set to say 100, it'll set the actual lifetime to be randomly chosen between $LIFETIME - 100 and $LIFETIME + 100, so things die a bit less predictable. Helps stabilize the simulations too when you're doing reproduction too.
- vimgrinder 1y agoyes had the same idea but applied that by doing randomization in age: floor(random(0, this.lifespan)) for me its not vanishing suddenly, so not sure how to reproduce now
- anigbrowl 1y agoBoids vanishing
- deleted 1y ago[deleted]
- throw_m239339 1y agoI remember that word "Boids" from Blender Physic simulation menu, to mimic a flock of birds in 3D, I also remember understanding nothing to its settings, but it kind of worked well.
- deleted 1y ago[deleted]
- chachacharge 1y agoGreen light is perceived as brighter than other colors because human eyes are most sensitive to it. This sensitivity is related to the wavelengths of light that our visual system responds to, with green being at the peak of our vision
- animal531 1y agoI quite like Boids, but recently I started playing with RVO2 ORCA (optimal reciprocal collision avoidance). I made some changes to it and moved it to a compute shader to make this: https://www.youtube.com/watch?v=BavnPOPcHlk https://www.youtube.com/watch?v=BavnPOPcHlk The entities in the video are running super fast for testing purposes, so usually they'd be going a lot slower. They can produce some really pleasing patterns as they move through each other etc. On the downside its quite expensive vs Boids, for example the video is from a slightly older version and every agent is looking at the closest 32 neighbours + 32 obstacles to compute its own velocity. At high densities you can drop that to e.g. 4 neighbours without appreciable difference, which allows for running e.g. 32k entities at 120fps.
- adanto6840 1y agoI've done a lot of work on realtime obstacle avoidance that scales well (targeting ~60-100k agents) -- steering behaviors, flow fields, RVO2/ORCA, and lots more -- for agent-based "old school" tycoon-style simulation games. :) I'm super intrigued by what you've created, especially to hear about running it in a compute shader! I'd love to talk with you more about it, if you're open to it? I briefly looked for a way to get in touch directly but didn't see any contact info -- my email is in my profile, I'd love to connect! :)