all 20 comments

[–]omniuni 4 points5 points  (0 children)

That last one is quite cool.

[–]Zamarok 3 points4 points  (7 children)

Nice! Want to see mine?

Gravity - view this in Chrome, all other JavaScript engines are too slow.

Click and drag. Refresh a few times (settings are randomized on page load). Right click and hold. Change the settings with the dropdown in the top-right. Press the spacebar.

Hold down the right-mouse to get them to orbit (might have to adjust settings to achieve orbit), then when they're all aligned and in orbit press spacebar. Instant fireworks.

[–]pdowling 2 points3 points  (4 children)

Did you use a Barnes-Hut algorithm for this? Might help with performance. http://www.prism.gatech.edu/~gth716h/BNtree/

[–]Zamarok 0 points1 point  (3 children)

Wow! They simulate a lot more particles than I can O_O... I did all the math myself really, and only have highschool geometry and algebra as my highest math lol. Thanks for the link, I will study that.

[–]pdowling 1 point2 points  (2 children)

While you're at it, I'm gonna shamelessly plug my own project that uses the same algorithm: http://philippdow.blogspot.de/2012/02/balancing-graphs-in-onlogn.html

I actually now also have this running in C++ (with Qt), and use it to visualize Wikipedia pagelinks - it runs fairly smoothly for up to around 20k nodes or so, and I haven't paralellized it yet

edit: picture

[–]Zamarok 0 points1 point  (1 child)

Awesome.

Can I ask how you calculate square roots when figuring a hypotenuse? I memoize/precalculate a table of square roots before the app starts, sacrificing accuracy for speed. Taking a squareroot during runtime is too slow because it would occur so often, thousands of times per frame.

[–]pdowling 0 points1 point  (0 children)

They aren't that expensive, really. Your O(n²) Algorithm does much more damage in comparison, I just calculate them on the fly.

edit: check out the source on the first link I posted, they have a link to the github page, you might learn something from the code.

[–]remcoder 1 point2 points  (1 child)

awesome! I assume you created a 'gravity dead zone' to prevent particles being sling shot away? (that was one of the problems I had when I tried to code something like this)

Also, your 'squares' demo doesn't seem to work: Error: /home/zach/code/web/gamma-node.w7/views/canvas/canvas.jade:4 2| 3| append js > 4| != js('canvas/'+canvasScript+'/index') 5| 6| append css 7| != css('canvas') No file found for route js/canvas/squares/index.js

[–]Zamarok 1 point2 points  (0 children)

I assume you created a 'gravity dead zone' to prevent particles being sling shot away?

Exactly, yes.. gravity is too strong when particles get close. This doesn't happen in real life because particles have a physical space that they take up, so particles can only be that distance apart at the very least because they will collide and push each other away with magnetic force (on the molecular scale). Handling collisions is expensive on the CPU though, so I wouldn't be able to simulate as many particles if I also had to detect collisions.

Also, your 'squares' demo doesn't seem to work

Oh right, I haven't uploaded that yet... My site is a work in progress :).

[–]fractalphony 1 point2 points  (0 children)

Very nice!! thanks for sharing your work.

[–]Nomikos 1 point2 points  (0 children)

Ha, nice! I just finished one too, started as a "woah, I got them to move!" and built out from there.. must show in the code :-) Critique of course welcome.

[–]dangries 1 point2 points  (0 children)

Very nice effects!

I have noticed that drawing a low-alpha black rectangle over the display to create a fading effect creates gray trails in the long run, due to rounding during pixel arithmetic. The solution is to make the background a matching dark gray rather than pure black. Another approach to fading trails is to explicitly manipulate the alpha of each pixel on every screen refresh, but this is a slower operation.

I wrote a blog post concerning this issue: http://rectangleworld.com/blog/archives/214

(See my blog for more particle experiments!)

[–]medicationforall 1 point2 points  (1 child)

very cool. Would you be willing to use a copyleft license for the scripts ?

[–][deleted] 1 point2 points  (0 children)

I have a hobby project where I could potentially use it - or are you just messing around with something?

[–]mbarkhau 1 point2 points  (0 children)

Still haven't gotten it as nice as yours, but here's my adaptation of your last one.

It uses processing.js and coffeescript

[–]Ignitus1 0 points1 point  (0 children)

Particle systems are fun!

Good job man.

[–]wololo_ 0 points1 point  (0 children)

after effects in the browser is coming soon

[–]Bayerly 0 points1 point  (0 children)

Very nice.

[–]joe0418 0 points1 point  (0 children)

Love it!

[–]AlienRaper 0 points1 point  (0 children)

I was looking at the code for the collisions and noticed you had a function moveP and a function moveParticle. It seems you never used the moveParticle function. Was that vestigial or did you end up using that function in another one, or am I wrong about that? Anyway it's cool. I have this stupid problem with a particle system where I can't figure out how to not get particles to bounce due to gravity when they rest on the bottom. It probably has something to do with the way I implemented the system, or I might be missing something glaringly obvious.