Loading...

2D Fluid Simulation in Javascript

11,693 views

Loading...

Loading...

Rating is available when the video has been rented.
This feature is not available right now. Please try again later.
Published on May 11, 2012

2D Fluid Simulation in Javascript - try it here: http://p.brm.sk/fluid/

using IvanK engine: http://lib.ivank.net/?p=demos

far-away-goal is to make 2D game like Dwarf Fortress

SPH (smooth particle hydrodynamics)
based on (academically unreadable) Clavet 2005
Particle-Based Viscoelastic Fluid Simulation

pdf: http://www.iro.umontreal.ca/labs/info...
mirror: http://citeseerx.ist.psu.edu/viewdoc/...

music: 班得瑞乐团 - 清澈海洋 :)

------------------------------------------------------------
Simplified, this is what it does (wish somebody gave this explanation to me):

FOREACH PARTICLE p
` p.vel = (pos - posOld) / dt
` p.posOld = pos
` p.vel += gravity * dt
` p.pos += p.vel * dt
` p.dens = 0
` p.densN = 0

FOREACH PARTICLE p
` FOREACH PARTICLE p2
` ` if (dist(p,p2) < K_smoothingRadius)
` ` ` createPair(p, p2)

FOREACH PAIR p (of particles A B)
` Q = 1 - dist(A, B) / K_smoothingRadius
` p.q2 = Q^2
` p.q3 = Q^3
` A.dens += Q2
` B.dens += Q2
` A.densN += Q3
` B.densN += Q3

FOREACH PARTICLE p
` p.press = K_stiff * (p.dens - K_restDensity)
` p.pressN = K_stiffN * p.densN

FOREACH PAIR p (of particles A B)
` press = A.press + B.press
` pressN = A.pressN + B.pressN
` displace = (press*p.q2 + press*p.q3) *(dt^2)
` a2bN = directionNormal(A, B) // or b2a
` A.pos += displace * a2bN
` B.pos -= displace * a2bN

Loading...

When autoplay is enabled, a suggested video will automatically play next.

Up next


to add this to Watch Later

Add to

Loading playlists...