wully616 / phaser-fluid Goto Github PK
View Code? Open in Web Editor NEWfluid sim in phaser 3
fluid sim in phaser 3
the ink density is not mass conserving, when applying a vector on a grid with velocity the whole thing gets advected and essentially overwrites what is in the new field with what was in the old field
float epsilon=2;
void add_vorocity(int N, float * u, float * v, float dt) {
//vort is just the curl of the velocity field
#define vort(i,j) (( -0.5*( v[IX(i+1,j)]-v[IX(i-1,j)] + u[IX(i,j-1)]-u[IX(i,j+1)] )*N ))
int i, j;
int size = (N+2)*(N+2);
float *fx = (float *) malloc ( size*sizeof(float) );
float *fy = (float *) malloc ( size*sizeof(float) );
FOR_EACH_CELL
if(i==1 || j==1 || i==N || j==N) continue;
float dvx = 0.5*(vort(i+1,j)-vort(i-1,j));
float dvy = 0.5*(vort(i,j+1)-vort(i,j-1));
float mag=sqrt(dvx*dvx+dvy*dvy);
//apply a force equal to epsilon * cross(N,vor)
fx[IX(i,j)]=mag > smallf ? epsilon*dt*dvy*vort(i,j)/(mag*N) : 0;
fy[IX(i,j)]=mag > smallf ? epsilon*dt*dvx*vort(i,j)/(mag*N) : 0;
END_FOR
set_bnd ( N, 0, fx ); set_bnd ( N, 0, fy );
FOR_EACH_CELL
if(i==1 || j==1 || i==N || j==N) continue;
if(u[IX(i,j)]) u[IX(i,j)]+=fx[IX(i,j)];
if(v[IX(i,j)]) v[IX(i,j)]-=fy[IX(i,j)];
END_FOR
set_bnd ( N, 1, u ); set_bnd ( N, 2, v );
free(fx);
free(fy);
#undef vort
for (int x = 0; x < m_w-1; x++) {
for (int y = 0; y < m_h-1; y++) {
int cell = Cell(x,y);
float force_x = mp_p0[cell] - mp_p0[cell+1];
float force_y = mp_p0[cell] - mp_p0[cell+m_w];
mp_xv1[cell] += a * force_x;
mp_xv1[cell+1] += a * force_x;
mp_yv1[cell] += a * force_y;
mp_yv1[cell+m_w] += a * force_y;
}
http://www.cse.yorku.ca/~amana/research/grid.pdf
Currently the linear interpolater misses walls
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.