-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathattempt3Dconservedxyz_layers.pde
159 lines (134 loc) · 3.5 KB
/
attempt3Dconservedxyz_layers.pde
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 2:1 ration works best for visuals.
int nx = 200;
int ny = 100;
int nz = 100;
float D = 0.6;
float A = 1.3;
// 0.16666666 was found to work the best for 2D
float cons = .095; // 0.095 was found to work the best for 3D
float low = -0.001;
float high = 0.001;
int step = 0;
float cellSize;
float[][][] curr, nextA, nextB;
float thetaX, thetaY;
float rspeed = 1;
int width3D;
int pos = 0; // loop from 0 -> nx-1
int modRate = 1; // lower = faster
void setup() {
size(1200, 600, P3D);
width3D = width/2;
cellSize = width3D / (float)max(nx, ny, nz);
curr = new float[nx][ny][nz];
nextA = new float[nx][ny][nz];
nextB = new float[nx][ny][nz];
// init system
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
curr[i][j][k] = map(random(0, 1), 0, 1, low, high);
}
}
}
//beware of pbc here. just don't go all the way to the edge.
int x = nx/2;
int y = ny/2;
int z = nz/2;
curr[x][y][z] = 1;
curr[x][y+1][z] = 1;
curr[x+1][y][z] = 1;
curr[x+1][y+1][z] = 1;
curr[x][y][z+1] = 1;
curr[x][y+1][z+1] = 1;
curr[x+1][y][z+1] = 1;
curr[x+1][y+1][z+1] = 1;
thetaX = -PI/5;
thetaY = -PI/5;
}
void draw() {
background(31);
step++;
println(step);
if (step == 1201) {
noLoop();
}
// next A
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
float[] act = getActivity(curr, i, j, k, nx, ny, nz);
float A1 = act[0];
float A2 = act[1];
nextA[i][j][k] = (float)(A*Math.tanh(curr[i][j][k]) + D*(cons*(A1 + A2/2) - curr[i][j][k]));
}
}
}
// next B
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
float[] actA = getActivity(curr, i, j, k, nx, ny, nz);
float A1 = actA[0];
float A2 = actA[1];
float[] actB = getActivity(nextA, i, j, k, nx, ny, nz);
float B1 = actB[0];
float B2 = actB[1];
nextB[i][j][k] = nextA[i][j][k] - cons*(B1-A1) - cons*(B2-A2)/2;
}
}
}
// update and draw
pushMatrix();
translate(width3D/2-150, height/2, -width3D*1.5/3);
rotateX(thetaX);
rotateY(thetaY);
int offx = -nx/2;
int offy = -ny/2;
int offz = -nz/2;
pushMatrix();
noStroke();
fill(255, 255);
rectMode(CENTER);
translate(-width3D/2+pos*cellSize, 0, 0);
rotateY(PI/2);
int lip = 25;
rect(cellSize/2, -cellSize/2, nz*cellSize+lip, ny*cellSize+lip);
popMatrix();
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
for (int k = 0; k < nz; k++) {
curr[i][j][k] = nextB[i][j][k];
color val = lerpColor(0, 255, (curr[i][j][k]+1)/2);
fill(val, val);
noStroke();
pushMatrix();
translate((i+offx)*cellSize, (j+offy)*cellSize, (k+offz)*cellSize);
box(cellSize);
popMatrix();
}
}
}
popMatrix();
stroke(255);
strokeWeight(2);
line(width/2, 0, width/2, height);
float newCellSize = cellSize*1.5;
float off = width3D/2-ny*newCellSize/2;
for (int k = 0; k < nz; k++) {
for (int j = 0; j < ny; j++) {
color val = lerpColor(0, 255, (curr[pos][j][k]+1)/2);
fill(val, val);
noStroke();
rectMode(CORNER);
rect(width3D+(nz-1-k)*newCellSize+off, j*newCellSize+off, newCellSize, newCellSize);
}
}
if (step % modRate == 0) {
pos++;
if (pos > nx-1) {
pos = 0;
}
}
saveFrame("frames/"+nx+"."+ny+"."+nz+"_"+D+"_"+A+"_"+abs(low)+"_"+abs(high)+"_layers/####.png");
}