-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluid_sim.js
63 lines (44 loc) · 1004 Bytes
/
fluid_sim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
elem = document.getElementById("container");
setCanvas(elem);
w = WIDTH;
h = HEIGHT;
t = 0;
i = 0;
ii = 5 ;
function gauss_seidel(A,x=[0,0,0],B){
n=A.length;
for(i=0;i<n;i++){
d=B[i];
for(j=0;j<n;j++){
if(i!=j){
d-=A[i][j]*x[j];
}
}
x[i]=d/A[i][i];
}
return x;
}
/*
a=[[4, 1, 2],[3, 5, 1],[1, 1, 3]]
x=[0,0,0];
b=[4,7,3];
for(m=0;m<25;m++){
x=gauss_seidel(a,x,b);
console.log(x);
}
*/
function draw() {
clearCanvas();
simulate(0.1);
for(i=1;i<N;i++){
for(j=1;j<N;j++){
val=sqrt(u[IX(i,j)]*u[IX(i,j)]+v[IX(i,j)]*v[IX(i,j)]);
c=`hsl(${mapRange(val,0,0.0001,0,360)},100%,50%)`;
new rect(i,j,ii,ii,c,1,"#fff",0);
}
}
requestAnimationFrame(draw);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
draw();