TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JavaScript particle simulator

271 pointsby filipedeschampsover 11 years ago

31 comments

DanielRibeiroover 11 years ago
If you liked this, Chrome Experiments is filled with particle examples: <a href="http://www.chromeexperiments.com/search/results.html?q=particles" rel="nofollow">http:&#x2F;&#x2F;www.chromeexperiments.com&#x2F;search&#x2F;results.html?q=parti...</a><p>Three.js also has some pretty nice to follow particles samples:<p><a href="http://threejs.org/examples/#webgl_particles_random" rel="nofollow">http:&#x2F;&#x2F;threejs.org&#x2F;examples&#x2F;#webgl_particles_random</a><p><a href="http://threejs.org/examples/#webgl_particles_sprites" rel="nofollow">http:&#x2F;&#x2F;threejs.org&#x2F;examples&#x2F;#webgl_particles_sprites</a><p><a href="http://threejs.org/examples/#webgl_buffergeometry_particles" rel="nofollow">http:&#x2F;&#x2F;threejs.org&#x2F;examples&#x2F;#webgl_buffergeometry_particles</a>
theGimpover 11 years ago
The frame rate is incredible given the number of particles. JavaScript interpreters really have come a long way. The frame rate for JS particle simulation beats the frame rate you get when you tell a browser to append content, which is usually native C&#x2F;C++ optimized to death.<p>To the author: great work. It looked very much alive on my screen when I first loaded the page.
评论 #6765531 未加载
评论 #6765383 未加载
arturventuraover 11 years ago
Does anyone have the theoretical description of what is happening? I&#x27;m curious about the fractal patterns being generated and the increasing in entropy and the that results in a catastrophic failure of the stable system. Is this some kind of chaotic system or is just an force field being applied on the particules.
评论 #6767059 未加载
technotonyover 11 years ago
This is beautiful, after watching I feel like I finally understand how the universe developed structure after the big bang.
clarkmoodyover 11 years ago
I would love to see a choice of initial conditions, one of which being a couple &#x27;galaxies&#x27; of particles on a collision course.<p>Also, a way to reset the simulation without reloading the page would be nice.
评论 #6765743 未加载
评论 #6765368 未加载
joshuover 11 years ago
The presentation this is from is at <a href="http://www.cake23.de/fmx/" rel="nofollow">http:&#x2F;&#x2F;www.cake23.de&#x2F;fmx&#x2F;</a> - there&#x27;s a lot more good stuff inside than just this.
DanBCover 11 years ago
Y U NO SUPPORT OES_texture_float_linear?<p>Using Version 31.0.1650.57 m Google Chrome is up to date
评论 #6765412 未加载
d23over 11 years ago
I find this infinitely more interesting than the recent &quot;X in 2.3 lines of JS&quot; trend lately.
评论 #6766424 未加载
iLochover 11 years ago
So how long do I have to wait to see it go back to it&#x27;s initial position? (Theoretically...)
Flexi23over 11 years ago
I&#x27;m the original author of this little WebGL experiment and i want to try to answer some questions that came up here.<p>1) implementation there&#x27;s quite some boilerplate in JS to set up all the textures and the main animation loop, but if you look closely the CPU is mostly idle and the &quot;heavy lifting&quot; is all done on the GPU by several shader programs. There are no libraries used and you can take a copy of the html file and simply start by breaking things apart. For the massive speed I&#x27;m updating the particle data with a clever fragment shader trick that i&#x27;ve learned from <a href="https://twitter.com/BlurSpline/status/161806273602519040" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;BlurSpline&#x2F;status&#x2F;161806273602519040</a> And in a DIY fashion, I&#x27;ve mashed this up with my own texture feedback loop. The main idea is that the particle positions (and the velocity vectors too, each 2D only) are stored in a texture&#x27;s rgba values (float32). So updating the particles data is in fact a render process of a quad in one draw call. Then I had also rendered the particles to another texture to sum up the &quot;density&quot; of the primitive 1 pixel point projections.<p>2) complexity when it comes to the mere particle count, the complexity really is O(n), but there&#x27;s a wee bit more to it. The projection of the particles to the framebufferobject or the screen is the most costly in this setup and it&#x27;s fillrate-limited by the graphics card. There&#x27;s a noticeable difference when the particles are evenly distributed or when they overlap, but it must stay in the O(n) realm i suppose. Then there&#x27;s another texture feedback loop system that is also directly dependent on the pixel count. The particles are stored in a 1024x512 pixels wide texture and the hidden texture feedback layer is also of that size, but it could differ too. There is absolutely no direct interaction between any two particles here. I project the particles to a density texture that is then diffused with an optimized two-pass Gaussian blur calculation and several resolution reduction steps. All the textures from the different steps are available as in put sampler to the shader programs, in particular &quot;fs-advance&quot; for the Turing patterns and the density projection (hey there, the blue channel is unused ^^) and &quot;fs-move-particles&quot; where i simply grab the gradient from the diffused density to update the particle&#x27;s velocity vector and do the verlet integration.<p>The concepts used here also have names - just ask google or wikipedia for &quot;dissipative systems&#x2F;structures&quot; and &quot;stigmergy&quot;.<p>3) the fluid simulation code is not by me! Evgeny Demidov is the original author of the WebGL shaders for that: <a href="http://www.ibiblio.org/e-notes/webgl/gpu/fluid.htm" rel="nofollow">http:&#x2F;&#x2F;www.ibiblio.org&#x2F;e-notes&#x2F;webgl&#x2F;gpu&#x2F;fluid.htm</a> I&#x27;m only adding to the current advection matrix<p>4) code size this could possibly fit into a 4k demo but i have no interest in that kind of challenge. i rather like to share something that is easily readable by others.<p>cheers!
评论 #6767378 未加载
评论 #6767700 未加载
pwnnaover 11 years ago
How is this made?<p>It&#x27;s pretty slow on my computer. Would ASM.js work better?
评论 #6765158 未加载
评论 #6765222 未加载
tumesover 11 years ago
Yes, but how many lines of javascript? It seems that&#x27;s the metric above all metrics lately.
spectre256over 11 years ago
but is it done in 30 lines of javascript? (i checked, no)
vjoelover 11 years ago
Took me a long time to notice that my cursor movements were injecting disturbances into the fluid. What physical laws govern these points, and how is the cursor perturbing them?
评论 #6765462 未加载
ffrryuuover 11 years ago
I don&#x27;t think that&#x27;s how particles work?
评论 #6765226 未加载
crashandburn4over 11 years ago
is there anything detailing the maths&#x2F;programming techniques behind this? can anyone confirm whether this is Barnes-Hut?<p>I&#x27;ve had a look here: <a href="http://creativejs.com/2013/11/coupled-turing-pattern-and-219-particles/" rel="nofollow">http:&#x2F;&#x2F;creativejs.com&#x2F;2013&#x2F;11&#x2F;coupled-turing-pattern-and-219...</a><p>but there&#x27;s no details on the specifics
评论 #6767067 未加载
stuartdover 11 years ago
Meh. U no support my 6 year old MacBook with crappy integrated graphics? Nothing on Safari 6.1, Firefox 25, Chrome 31..
Bhelover 11 years ago
Cute, although not the best performance.<p>It&#x27;d be nice if the color gradually changed.
评论 #6766281 未加载
adcuzover 11 years ago
How do you even begin to write something like this?
nniover 11 years ago
Maybe we&#x27;re written in 30 lines of javascript, too. You can get - to us - surprisingly and beautiful complexity from simple rules.
j2kunover 11 years ago
Is this doing anything smarter than brute force and having the graphics primitives do the heavy lifting?
grogenautover 11 years ago
Man I thought we were done with &quot;Look at this 1998 era screen saver I made with webgl&quot;
sengstromover 11 years ago
It seems like the ensemble heats up. Could it get a little energy dissipation?
contrahaxover 11 years ago
Black screen Chrome 31 OSX
评论 #6765620 未加载
filipedeschampsover 11 years ago
To be honest, I would love to play a game out of this.
评论 #6765554 未加载
ponyousover 11 years ago
In how many lines?
tomrodover 11 years ago
No mobile!
评论 #6765560 未加载
评论 #6765525 未加载
CmonDevover 11 years ago
Does not work.
andreea_popescuover 11 years ago
Awesome!
benihanaover 11 years ago
I will never get tired of seeing these kinds of posts on HN.
评论 #6765568 未加载
lectricover 11 years ago
Since a load of unfeeling morons have taken over HN, let me say for them that this was amazing. Thank you.<p>I really <i>can</i> <i>not</i> <i>wait</i> until there is some new community to which these unemotional sociopaths can wander.
评论 #6770730 未加载