-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
510 lines (454 loc) · 13.5 KB
/
index.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<style>
body {
margin: 0px;
overflow: hidden;
}
</style>
<body>
<script src="libraries/three.min.js"></script>
<script src="libraries/dat.gui.min.js"></script>
<script src="libraries/guify.js"></script>
<script id="vertexShader" type="x-shader/x-fragment">
varying vec2 vUv;
void main()
{
vUv = uv;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}
</script>
<script id="rule_ca" type="x-shader/x-fragment">
uniform int u_rule[16];
uniform vec2 u_resolution;
uniform vec3 u_mouse;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
uniform float u_mouseSize;
uniform vec3 u_newLifeColor;
uniform vec3 u_survivorColor;
uniform int u_paused;
uniform float u_colors[18];
float v(float xrel, float yrel) {
// Takes input relative to current pixel and returns pixel value.
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution).a;
}
void main() {
float minRes = min(u_resolution.x, u_resolution.y);
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / minRes;
float inputSize = u_mouseSize / minRes;
float fate = float(v(0.,0.) == 1.);
if(u_frameCount < 2) {
//create random initial texture first 2 frames of program
if (int(gl_FragCoord.x) == int(float(u_resolution.x) / 2.0) && int(gl_FragCoord.y) == int(float(u_resolution.y) / 2.0)) {
fate = 1.0;
}
}
else if (u_paused == 1) {
int idx = int(v(-1., 1.)) * 1 + int(v(1., 1.)) * 2 + int(v(-1., -1.)) * 4 + int(v(1., -1.)) * 8;
for (int i = 0; i < 16; ++i) {
if (i == idx) {
fate = float(u_rule[i]);
}
}
}
gl_FragColor = vec4(fate);
}
</script>
<script id="life_ca" type="x-shader/x-fragment">
uniform vec2 u_resolution;
// uniform vec3 u_mouse;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
uniform int u_surviveLength;
uniform int u_bornLength;
// uniform float u_mouseSize;
// uniform vec3 u_newLifeColor;
// uniform vec3 u_survivorColor;
uniform int u_born[8];
uniform int u_survive[8];
uniform int u_paused;
//random noise function for initial texture
highp float rand(vec2 co)
{
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt= dot(co.xy ,vec2(a,b));
highp float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
float v(float xrel, float yrel) {
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution).a;
}
float neighborSum() {
return v(-1.,-1.) +
v(-1.,0.) +
v(-1.,1.) +
v(0.,-1.) +
v(0.,1.) +
v(1.,-1. )+
v(1.,0.) +
v(1.,1.);
}
// int includes(float v, int arr[8], int limit) {
// for (int i = 0; i < 8; ++i) {
// if (i > limit - 1) {
// return 1;
// }
// }
// return 1;
// }
void main()
{
float minRes = min(u_resolution.x, u_resolution.y);
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / minRes;
// float inputSize = u_mouseSize / minRes;
float fate = float(v(0.,0.) == 1.);
float before = fate;
if(u_frameCount < 2) //create random initial texture first 2 frames of program
{
float _rand = rand(uv*u_time);
fate = clamp(floor(_rand * _rand * _rand * 1.2), 0., 1.);
}
else if (u_paused == 1)//calculate neighbor totals
{
float sum = neighborSum();
bool a = (sum == 3. || (fate==1. && (sum == 2.)));
fate = float(a);
}
// bool userInput = (u_mouse.z > 0.) &&
// ((uv.x >= u_mouse.x - inputSize && uv.x < u_mouse.x + inputSize) &&
// (uv.y >= u_mouse.y - inputSize && uv.y < u_mouse.y + inputSize));
//
// fate += float(userInput);
gl_FragColor = vec4(fate);
//change color based on status change
// if(fate != before) {
// gl_FragColor = vec4(vec3(u_survivorColor)/255.,fate);
// } else if (before == fate && v(0.,0.) == 1.) {
// gl_FragColor = vec4(vec3(u_newLifeColor)/255.,fate);
// }
}
</script>
<script id="cyclic_ca" type="x-shader/x-fragment">
uniform float u_time;
uniform vec2 u_resolution;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
uniform int u_c;
uniform int u_r;
uniform int u_t;
uniform bool u_moore;
uniform int u_paused;
varying vec2 vUv;
float v(float xrel, float yrel) {
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution).r;
}
highp float rand(vec2 co)
{
// random function
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt= dot(co.xy ,vec2(a,b));
highp float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
float initialize()
{
float r = rand(gl_FragCoord.xy + vec2(40.0, 2000.0));
return floor(r * float(u_c) + 1e-10) / float(u_c);
}
int cellState(vec2 delta)
{
return int((float(u_c) * texture2D(u_currentTexture, vec2(mod(vUv.x + delta.x, 1.0), mod(vUv.y + delta.y, 1.0))).r) + 0.5);
}
bool match(int mid, vec2 delta)
{
vec2 d = (1.0) / u_resolution;
if (mid == cellState(delta))
return true;
return false;
}
int sumNM(int mid, vec2 d)
{
// Moore neighborhood
int sum = 0;
for (int x = 0; x <= 20; ++x)
{
if (x == u_r * 2 + 1)
break;
for (int y = 0; y <= 20; ++y)
{
if (x == u_r && y == u_r)
continue;
if (y == u_r * 2 + 1)
break;
if (match(mid, vec2((float(x - u_r)) * d.x, (float(y - u_r)) * d.y)))
sum += 1;
}
}
return sum;
}
int sumNN(int mid, vec2 d)
{
// Von Neumann neighborhood
int sum = 0;
for (int x = 0; x <= 20; ++x)
{
if (x == u_r * 2 + 1)
break;
for (int y = 0; y <= 20; ++y)
{
if (x == u_r && y == u_r)
continue;
if (y == u_r * 2 + 1)
break;
if (float(u_r) < (abs(float(x - u_r)) + abs(float(y - u_r))))
continue;
if (match(mid, vec2(float(x - u_r) * d.x, float(y - u_r) * d.y)))
sum += 1;
}
}
return sum;
}
float calc()
{
vec2 d = (1.0) / u_resolution;
int cell = cellState(vec2(0.0, 0.0));
int mid = cell - 1;
if (mid < 0) mid = u_c - 1;
int sum = 0;
if (u_moore)
sum = sumNN(mid, d);
else
sum = sumNM(mid, d);
if (u_t <= sum)
cell = mid;
return float(cell) / float(u_c);
}
void main()
{
float r = v(0.,0.);
if (u_frameCount < 2)
r = initialize();
else if (u_paused == 1)
r = calc();
gl_FragColor = vec4(r, mod(r * 2.6, 1.), mod(r * 6.4, 1.), 1.);
}
</script>
<script id="gray_scott" type="x-shader/x-fragment">
uniform vec2 u_resolution;
// uniform vec3 u_mouse;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
// uniform float u_mouseSize;
uniform int u_paused;
uniform float u_time;
uniform int u_t;
uniform int u_r;
uniform int u_c;
uniform bool u_moore;
float feed = .0367;
float kill = .0649;
float delta = 1.;
uniform int u_w;
uniform int u_h;
float dA = 1.0;
float dB = 0.4;
vec2 v(float xrel, float yrel) {
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution).rg;
}
void main() {
if(u_frameCount < 20) //create random initial texture first 2 frames of program
{
if (abs(gl_FragCoord.x - float(u_w) / 2.) < 10. && abs(gl_FragCoord.y - float(u_h) / 2.) < 10.) {
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 10; ++j) {
gl_FragColor = vec4(1., 1., 0., 1.);
}
}
} else {
gl_FragColor = vec4(1., 0., 0., 1.);
}
}
else if (u_paused == 1) {
vec2 uv = v(0.,0.);
vec2 uv0 = v(-1.,0.);
vec2 uv1 = v(1.,0.);
vec2 uv2 = v(0.,-1.);
vec2 uv3 = v(0.,1.);
vec2 uv4 = v(-1.,-1.);
vec2 uv5 = v(1.,1.);
vec2 uv6 = v(1.,-1.);
vec2 uv7 = v(-1.,1.);
vec2 lapl = (uv0 * .2 + uv1 * .2 + uv2 * .2 + uv3 * .2 + uv4 * .05 + uv5 * .05 + uv6 * .05 + uv7 * .05 - uv);//10485.76;
float du = /*0.00002*/dA*lapl.r - uv.r*uv.g*uv.g + feed*(1.0 - uv.r);
float dv = /*0.00001*/dB*lapl.g + uv.r*uv.g*uv.g - (feed+kill)*uv.g;
vec2 dst = uv + 1.*vec2(du, dv);
gl_FragColor = vec4(dst.r, dst.g, 0.0, 1.0);
}
}
</script>
<script id="symm_ca" type="x-shader/x-fragment">
uniform vec2 u_resolution;
// uniform vec3 u_mouse;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
// uniform float u_mouseSize;
uniform int u_paused;
uniform float u_time;
uniform int u_t;
uniform int u_r;
uniform int u_c;
uniform bool u_moore;
uniform int u_zeros[100];
uniform int u_ones[100];
bool inOnes(int idx) {
for (int i = 0; i < 100; ++i) {
if (idx == u_ones[i]) {
return true;
}
}
return false;
}
bool inZeros(int idx) {
for (int i = 0; i < 100; ++i) {
if (idx == u_zeros[i]) {
return true;
}
}
return false;
}
int pow(int idx) {
int val = 1;
for (int i = 0; i < 100; ++i) {
if (idx == i) {
return val;
}
val = val * 2;
}
return val;
}
highp float rand(vec2 co)
{
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt= dot(co.xy ,vec2(a,b));
highp float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
float v(float xrel, float yrel) {
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution).a;
}
int count() {
int val = 0;
int idx = 0;
for (int i = -1; i < 2; ++i) {
for (int j = -1; j < 2; ++j) {
if ((v(float(i), float(j)) - 1.) < .1) {
val += pow(idx);
}
idx += 1;
}
}
return val;
}
void main() {
float minRes = min(u_resolution.x, u_resolution.y);
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / minRes;
if(u_frameCount < 200) {
//create random initial texture first 2 frames of program
if (int(gl_FragCoord.x) == int(float(u_resolution.x) / 2.0) && int(gl_FragCoord.y) == int(float(u_resolution.y) / 2.0)) {
gl_FragColor = vec4(0.0);
} else {
gl_FragColor = vec4(1.0);
}
}
else if (u_paused == 1) {
int idx = 2;
if (inOnes(idx)) {
gl_FragColor = vec4(0.);
} else if (inZeros(idx)) {
gl_FragColor = vec4(1.);
} else {
gl_FragColor = vec4(v(0.,0.));
}
}
}
</script>
<script id="stepping_stone" type="x-shader/x-fragment">
uniform vec2 u_resolution;
// uniform vec3 u_mouse;
uniform sampler2D u_currentTexture;
uniform int u_frameCount;
// uniform float u_mouseSize;
uniform int u_paused;
uniform float u_time;
uniform int u_t;
uniform int u_r;
uniform int u_c;
uniform bool u_moore;
highp float rand(vec2 co)
{
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt= dot(co.xy ,vec2(a,b));
highp float sn= mod(dt,3.14);
return fract(sin(sn) * c);
}
vec4 v(float xrel, float yrel) {
vec2 xy;
xy.x = mod(gl_FragCoord.x + xrel, u_resolution.x);
xy.y = mod(gl_FragCoord.y + yrel, u_resolution.y);
return texture2D(u_currentTexture, xy/u_resolution);
}
void main() {
float minRes = min(u_resolution.x, u_resolution.y);
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / minRes;
vec4 fate = v(0.,0.);
if (u_frameCount < 2) {
float _rand = random(uv * 1.5 * u_time);
gl_FragColor = vec4(_rand);
}
else if (u_paused == 1) {
float _rand = rand(uv * 1.5 * u_time);
if (_rand < 0.5) {
float _rand2 = rand(uv * 1. * u_time) * 3.;
int n = int(sign(_rand2)*floor(abs(_rand2)+.5));
if (n == 0) {
gl_FragColor = v(0.,1.);
} else if (n == 1) {
gl_FragColor = v(1.,0.);
} else if (n == 2) {
gl_FragColor = v(0.,-1.);
} else if (n == 3) {
gl_FragColor = v(-1.,0.);
}
} else {
gl_FragColor = vec4(fate.r, fate.g, fate.b, 1.);
}
} else {
gl_FragColor = vec4(fate.r, fate.g, fate.b, 1.);
}
}
</script>
<script src="app.js"></script>
</body>