Live data from Hacker News

Show HN: Boids Simulation

anoopelias.github.io

11–20 of 31 posts

Re: Show HN: Boids Simulation

#11
post #3

Nice! I've done something similar in the past: http://static.mysti.co.in/boids/ Source: https://github.com/tech-no-crat/boids

If you use 'requestAnimationFrame()' instead of a 'setInterval()' for triggering your update method, your animation will perform a lot smoother:

https://developer.mozilla.org/en-US/docs/Web/API/window/requ...

Re: Show HN: Boids Simulation

#12
post #11
post #3

Nice! I've done something similar in the past: http://static.mysti.co.in/boids/ Source: https://github.com/tech-no-crat/boids

If you use 'requestAnimationFrame()' instead of a 'setInterval()' for triggering your update method, your animation will perform a lot smoother: https://developer.mozilla.org/en-US/docs/Web/API/window/requ...

Have a look at this one, highly recommended, https://github.com/hughsk/ticker

Re: Show HN: Boids Simulation

#13
Khan Academy has a good Natural Simulations in JS tract. https://www.khanacademy.org/computing/computer-programming/p...

It uses processing.js when I worked through it I just ended up implementing everything with canvas and making my own versions of the processing specific classes and functions needed.

Re: Show HN: Boids Simulation

#14
I think almost every AI-guy have tried making a boids simulation. They are such a good way to show emergent behavior from very simple rules.

I'm a TA for an AI-course at my uni, and this semester my students had to program a boids simulation for the first project. In addition to what's shown here, the boids also had to avoid obstacles and flee from predators. I think the students liked it, it's very rewarding to code and actually see the result.

The students also had to implement sliders, for how much cohesion, separation and alignment is weighted. It's pretty fun to change them and watch the behavior of the boids change.

Re: Show HN: Boids Simulation

#15

I was inspired by this to create my own a few months ago. It uses a quadtree to optimize nearest neighbor lookup to ideally reduce complexity from n^2 to nlogn on each tick. http://jrhdoty.github.io/SwarmJS/

Yes, looks beautiful. Quite similar, I guess. I had run in to some performance issues, the initial few ticks are quiet slow even now, esp. on a phone. This one uses a kdtree instead. I'll have to try quadtree and benchmark. Thanks.

The best data structure to use depends a lot on what you're actually doing with your neighbours.

If what you actually want to do is to have each boid be affected by each boid in a fixed-size neighbourhood, the best acceleration structure is actually just fixed-size bins.

Re: Show HN: Boids Simulation

#17
Ah, Boids! One of my favorite examples of systems that can be "embarassingly parallel". I managed to write (with very little optimisation - not even using quadtrees to optimise neighbour lookup) a GPU accelerated version about a year ago that managed to stay above 30fps even up to about 5000 individual agents.

It also hammered home the problem of device/host memory reigions which you've got to deal with when doing GPU programming. I found that other, simpler, systems didn't manage to get as much speedup as Boids did, as transferring data, not computation, was where they bottlenecked. With Boids, by contrast, I could keep everything (computation, and rendering) on the GPU, and never even have to touch the CPU, aside from calling various CUDA and OpenCL functions.

Re: Show HN: Boids Simulation

#19
post #14

I think almost every AI-guy have tried making a boids simulation. They are such a good way to show emergent behavior from very simple rules. I'm a TA for an AI-course at my uni, and this semester my students had to program a boids simulation for the first project. In addition to what's shown here, the boids also had to avoid obstacles and flee from predators. I think the students liked it, it's very rewarding to code…

Is the course content available online?
Post reply on HN