└── WebGL-Automata ├── TODO ├── glsl ├── 0.frag ├── BlurFilter.frag ├── PlaceCirclePierce.frag ├── TexMerge.frag ├── copy.frag └── quad.vert ├── gol.css ├── index.html ├── js ├── gol.js └── vendor │ ├── dat.gui.min.js │ └── stats.js └── lib ├── igloo-0.1.0.js └── jquery-2.1.1.min.js /WebGL-Automata/TODO: -------------------------------------------------------------------------------- 1 | - Add more render filters 2 | - Add in-game GLSL editor with automatically saved backup tree & revert function 3 | - Add parametermap explorer (click to select that pixel's rule) -------------------------------------------------------------------------------- /WebGL-Automata/glsl/0.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D tex0_in; 4 | uniform vec2 tex_size; 5 | 6 | float getR(vec2 offset) { 7 | return (texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).r); 8 | } 9 | 10 | float getG(vec2 offset) { 11 | return (texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).g); 12 | } 13 | 14 | float getB(vec2 offset) { 15 | return (texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).b); 16 | } 17 | 18 | float checkR(vec2 offset) { 19 | if ((texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).r) > 0.0) {return 1.0;} 20 | else {return 0.0;} 21 | } 22 | 23 | float checkG(vec2 offset) { 24 | if ((texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).g) > 0.0) {return 1.0;} 25 | else {return 0.0;} 26 | } 27 | 28 | float checkB(vec2 offset) { 29 | if ((texture2D(tex0_in, (gl_FragCoord.xy + offset) / tex_size).b) > 0.0) {return 1.0;} 30 | else {return 0.0;} 31 | } 32 | 33 | void main() { 34 | 35 | //Set the default values 36 | 37 | float cR = getR(vec2(0.0, 0.0)); 38 | float cG = getG(vec2(0.0, 0.0)); 39 | float cB = getB(vec2(0.0, 0.0)); 40 | 41 | gl_FragColor = vec4(cR, cR, cR, 1.0); 42 | 43 | //Sum the values of the Red Channel for 44 | //each of the neighbourhood coordinate groups 45 | 46 | float s0 = 47 | getR(vec2(-14.0, -1.0)) + 48 | getR(vec2(-14.0, 0.0)) + 49 | getR(vec2(-14.0, 1.0)) + 50 | getR(vec2(-13.0, -4.0)) + 51 | getR(vec2(-13.0, -3.0)) + 52 | getR(vec2(-13.0, -2.0)) + 53 | getR(vec2(-13.0, 2.0)) + 54 | getR(vec2(-13.0, 3.0)) + 55 | getR(vec2(-13.0, 4.0)) + 56 | getR(vec2(-12.0, -6.0)) + 57 | getR(vec2(-12.0, -5.0)) + 58 | getR(vec2(-12.0, 5.0)) + 59 | getR(vec2(-12.0, 6.0)) + 60 | getR(vec2(-11.0, -8.0)) + 61 | getR(vec2(-11.0, -7.0)) + 62 | getR(vec2(-11.0, 7.0)) + 63 | getR(vec2(-11.0, 8.0)) + 64 | getR(vec2(-10.0, -9.0)) + 65 | getR(vec2(-10.0, -1.0)) + 66 | getR(vec2(-10.0, 0.0)) + 67 | getR(vec2(-10.0, 1.0)) + 68 | getR(vec2(-10.0, 9.0)) + 69 | getR(vec2(-9.0, -10.0)) + 70 | getR(vec2(-9.0, -4.0)) + 71 | getR(vec2(-9.0, -3.0)) + 72 | getR(vec2(-9.0, -2.0)) + 73 | getR(vec2(-9.0, 2.0)) + 74 | getR(vec2(-9.0, 3.0)) + 75 | getR(vec2(-9.0, 4.0)) + 76 | getR(vec2(-9.0, 10.0)) + 77 | getR(vec2(-8.0, -11.0)) + 78 | getR(vec2(-8.0, -6.0)) + 79 | getR(vec2(-8.0, -5.0)) + 80 | getR(vec2(-8.0, 5.0)) + 81 | getR(vec2(-8.0, 6.0)) + 82 | getR(vec2(-8.0, 11.0)) + 83 | getR(vec2(-7.0, -11.0)) + 84 | getR(vec2(-7.0, -7.0)) + 85 | getR(vec2(-7.0, -2.0)) + 86 | getR(vec2(-7.0, -1.0)) + 87 | getR(vec2(-7.0, 0.0)) + 88 | getR(vec2(-7.0, 1.0)) + 89 | getR(vec2(-7.0, 2.0)) + 90 | getR(vec2(-7.0, 7.0)) + 91 | getR(vec2(-7.0, 11.0)) + 92 | getR(vec2(-6.0, -12.0)) + 93 | getR(vec2(-6.0, -8.0)) + 94 | getR(vec2(-6.0, -4.0)) + 95 | getR(vec2(-6.0, -3.0)) + 96 | getR(vec2(-6.0, 3.0)) + 97 | getR(vec2(-6.0, 4.0)) + 98 | getR(vec2(-6.0, 8.0)) + 99 | getR(vec2(-6.0, 12.0)) + 100 | getR(vec2(-5.0, -12.0)) + 101 | getR(vec2(-5.0, -8.0)) + 102 | getR(vec2(-5.0, -5.0)) + 103 | getR(vec2(-5.0, -1.0)) + 104 | getR(vec2(-5.0, 0.0)) + 105 | getR(vec2(-5.0, 1.0)) + 106 | getR(vec2(-5.0, 5.0)); 107 | float s1 = 108 | getR(vec2(-5.0, 8.0)) + 109 | getR(vec2(-5.0, 12.0)) + 110 | getR(vec2(-4.0, -13.0)) + 111 | getR(vec2(-4.0, -9.0)) + 112 | getR(vec2(-4.0, -6.0)) + 113 | getR(vec2(-4.0, -3.0)) + 114 | getR(vec2(-4.0, -2.0)) + 115 | getR(vec2(-4.0, 2.0)) + 116 | getR(vec2(-4.0, 3.0)) + 117 | getR(vec2(-4.0, 6.0)) + 118 | getR(vec2(-4.0, 9.0)) + 119 | getR(vec2(-4.0, 13.0)) + 120 | getR(vec2(-3.0, -13.0)) + 121 | getR(vec2(-3.0, -9.0)) + 122 | getR(vec2(-3.0, -6.0)) + 123 | getR(vec2(-3.0, -4.0)) + 124 | getR(vec2(-3.0, -1.0)) + 125 | getR(vec2(-3.0, 0.0)) + 126 | getR(vec2(-3.0, 1.0)) + 127 | getR(vec2(-3.0, 4.0)) + 128 | getR(vec2(-3.0, 6.0)) + 129 | getR(vec2(-3.0, 9.0)) + 130 | getR(vec2(-3.0, 13.0)) + 131 | getR(vec2(-2.0, -13.0)) + 132 | getR(vec2(-2.0, -9.0)) + 133 | getR(vec2(-2.0, -7.0)) + 134 | getR(vec2(-2.0, -4.0)) + 135 | getR(vec2(-2.0, -2.0)) + 136 | getR(vec2(-2.0, 2.0)) + 137 | getR(vec2(-2.0, 4.0)) + 138 | getR(vec2(-2.0, 7.0)) + 139 | getR(vec2(-2.0, 9.0)) + 140 | getR(vec2(-2.0, 13.0)) + 141 | getR(vec2(-1.0, -14.0)) + 142 | getR(vec2(-1.0, -10.0)) + 143 | getR(vec2(-1.0, -7.0)) + 144 | getR(vec2(-1.0, -5.0)) + 145 | getR(vec2(-1.0, -3.0)) + 146 | getR(vec2(-1.0, -1.0)) + 147 | getR(vec2(-1.0, 0.0)) + 148 | getR(vec2(-1.0, 1.0)) + 149 | getR(vec2(-1.0, 3.0)) + 150 | getR(vec2(-1.0, 5.0)) + 151 | getR(vec2(-1.0, 7.0)) + 152 | getR(vec2(-1.0, 10.0)) + 153 | getR(vec2(-1.0, 14.0)) + 154 | getR(vec2(0.0, -14.0)) + 155 | getR(vec2(0.0, -10.0)) + 156 | getR(vec2(0.0, -7.0)) + 157 | getR(vec2(0.0, -5.0)) + 158 | getR(vec2(0.0, -3.0)) + 159 | getR(vec2(0.0, -1.0)) + 160 | getR(vec2(0.0, 1.0)) + 161 | getR(vec2(0.0, 3.0)) + 162 | getR(vec2(0.0, 5.0)) + 163 | getR(vec2(0.0, 7.0)) + 164 | getR(vec2(0.0, 10.0)) + 165 | getR(vec2(0.0, 14.0)) + 166 | getR(vec2(1.0, -14.0)) + 167 | getR(vec2(1.0, -10.0)) + 168 | getR(vec2(1.0, -7.0)); 169 | float s2 = 170 | getR(vec2(1.0, -5.0)) + 171 | getR(vec2(1.0, -3.0)) + 172 | getR(vec2(1.0, -1.0)) + 173 | getR(vec2(1.0, 0.0)) + 174 | getR(vec2(1.0, 1.0)) + 175 | getR(vec2(1.0, 3.0)) + 176 | getR(vec2(1.0, 5.0)) + 177 | getR(vec2(1.0, 7.0)) + 178 | getR(vec2(1.0, 10.0)) + 179 | getR(vec2(1.0, 14.0)) + 180 | getR(vec2(2.0, -13.0)) + 181 | getR(vec2(2.0, -9.0)) + 182 | getR(vec2(2.0, -7.0)) + 183 | getR(vec2(2.0, -4.0)) + 184 | getR(vec2(2.0, -2.0)) + 185 | getR(vec2(2.0, 2.0)) + 186 | getR(vec2(2.0, 4.0)) + 187 | getR(vec2(2.0, 7.0)) + 188 | getR(vec2(2.0, 9.0)) + 189 | getR(vec2(2.0, 13.0)) + 190 | getR(vec2(3.0, -13.0)) + 191 | getR(vec2(3.0, -9.0)) + 192 | getR(vec2(3.0, -6.0)) + 193 | getR(vec2(3.0, -4.0)) + 194 | getR(vec2(3.0, -1.0)) + 195 | getR(vec2(3.0, 0.0)) + 196 | getR(vec2(3.0, 1.0)) + 197 | getR(vec2(3.0, 4.0)) + 198 | getR(vec2(3.0, 6.0)) + 199 | getR(vec2(3.0, 9.0)) + 200 | getR(vec2(3.0, 13.0)) + 201 | getR(vec2(4.0, -13.0)) + 202 | getR(vec2(4.0, -9.0)) + 203 | getR(vec2(4.0, -6.0)) + 204 | getR(vec2(4.0, -3.0)) + 205 | getR(vec2(4.0, -2.0)) + 206 | getR(vec2(4.0, 2.0)) + 207 | getR(vec2(4.0, 3.0)) + 208 | getR(vec2(4.0, 6.0)) + 209 | getR(vec2(4.0, 9.0)) + 210 | getR(vec2(4.0, 13.0)) + 211 | getR(vec2(5.0, -12.0)) + 212 | getR(vec2(5.0, -8.0)) + 213 | getR(vec2(5.0, -5.0)) + 214 | getR(vec2(5.0, -1.0)) + 215 | getR(vec2(5.0, 0.0)) + 216 | getR(vec2(5.0, 1.0)) + 217 | getR(vec2(5.0, 5.0)) + 218 | getR(vec2(5.0, 8.0)) + 219 | getR(vec2(5.0, 12.0)) + 220 | getR(vec2(6.0, -12.0)) + 221 | getR(vec2(6.0, -8.0)) + 222 | getR(vec2(6.0, -4.0)) + 223 | getR(vec2(6.0, -3.0)) + 224 | getR(vec2(6.0, 3.0)) + 225 | getR(vec2(6.0, 4.0)) + 226 | getR(vec2(6.0, 8.0)) + 227 | getR(vec2(6.0, 12.0)) + 228 | getR(vec2(7.0, -11.0)) + 229 | getR(vec2(7.0, -7.0)) + 230 | getR(vec2(7.0, -2.0)); 231 | float s3 = 232 | getR(vec2(7.0, -1.0)) + 233 | getR(vec2(7.0, 0.0)) + 234 | getR(vec2(7.0, 1.0)) + 235 | getR(vec2(7.0, 2.0)) + 236 | getR(vec2(7.0, 7.0)) + 237 | getR(vec2(7.0, 11.0)) + 238 | getR(vec2(8.0, -11.0)) + 239 | getR(vec2(8.0, -6.0)) + 240 | getR(vec2(8.0, -5.0)) + 241 | getR(vec2(8.0, 5.0)) + 242 | getR(vec2(8.0, 6.0)) + 243 | getR(vec2(8.0, 11.0)) + 244 | getR(vec2(9.0, -10.0)) + 245 | getR(vec2(9.0, -4.0)) + 246 | getR(vec2(9.0, -3.0)) + 247 | getR(vec2(9.0, -2.0)) + 248 | getR(vec2(9.0, 2.0)) + 249 | getR(vec2(9.0, 3.0)) + 250 | getR(vec2(9.0, 4.0)) + 251 | getR(vec2(9.0, 10.0)) + 252 | getR(vec2(10.0, -9.0)) + 253 | getR(vec2(10.0, -1.0)) + 254 | getR(vec2(10.0, 0.0)) + 255 | getR(vec2(10.0, 1.0)) + 256 | getR(vec2(10.0, 9.0)) + 257 | getR(vec2(11.0, -8.0)) + 258 | getR(vec2(11.0, -7.0)) + 259 | getR(vec2(11.0, 7.0)) + 260 | getR(vec2(11.0, 8.0)) + 261 | getR(vec2(12.0, -6.0)) + 262 | getR(vec2(12.0, -5.0)) + 263 | getR(vec2(12.0, 5.0)) + 264 | getR(vec2(12.0, 6.0)) + 265 | getR(vec2(13.0, -4.0)) + 266 | getR(vec2(13.0, -3.0)) + 267 | getR(vec2(13.0, -2.0)) + 268 | getR(vec2(13.0, 2.0)) + 269 | getR(vec2(13.0, 3.0)) + 270 | getR(vec2(13.0, 4.0)) + 271 | getR(vec2(14.0, -1.0)) + 272 | getR(vec2(14.0, 0.0)) + 273 | getR(vec2(14.0, 1.0)); 274 | float s4 = 275 | getR(vec2(-3.0, -1.0)) + 276 | getR(vec2(-3.0, 0.0)) + 277 | getR(vec2(-3.0, 1.0)) + 278 | getR(vec2(-2.0, -2.0)) + 279 | getR(vec2(-2.0, 2.0)) + 280 | getR(vec2(-1.0, -3.0)) + 281 | getR(vec2(-1.0, -1.0)) + 282 | getR(vec2(-1.0, 0.0)) + 283 | getR(vec2(-1.0, 1.0)) + 284 | getR(vec2(-1.0, 3.0)) + 285 | getR(vec2(0.0, -3.0)) + 286 | getR(vec2(0.0, -1.0)) + 287 | getR(vec2(0.0, 1.0)) + 288 | getR(vec2(0.0, 3.0)) + 289 | getR(vec2(1.0, -3.0)) + 290 | getR(vec2(1.0, -1.0)) + 291 | getR(vec2(1.0, 0.0)) + 292 | getR(vec2(1.0, 1.0)) + 293 | getR(vec2(1.0, 3.0)) + 294 | getR(vec2(2.0, -2.0)) + 295 | getR(vec2(2.0, 2.0)) + 296 | getR(vec2(3.0, -1.0)) + 297 | getR(vec2(3.0, 0.0)) + 298 | getR(vec2(3.0, 1.0)); 299 | float s5 = 300 | getR(vec2(-6.0, -1.0)) + 301 | getR(vec2(-6.0, 0.0)) + 302 | getR(vec2(-6.0, 1.0)) + 303 | getR(vec2(-5.0, -3.0)) + 304 | getR(vec2(-5.0, -2.0)) + 305 | getR(vec2(-5.0, -1.0)) + 306 | getR(vec2(-5.0, 0.0)) + 307 | getR(vec2(-5.0, 1.0)) + 308 | getR(vec2(-5.0, 2.0)) + 309 | getR(vec2(-5.0, 3.0)) + 310 | getR(vec2(-4.0, -4.0)) + 311 | getR(vec2(-4.0, -3.0)) + 312 | getR(vec2(-4.0, -2.0)) + 313 | getR(vec2(-4.0, -1.0)) + 314 | getR(vec2(-4.0, 0.0)) + 315 | getR(vec2(-4.0, 1.0)) + 316 | getR(vec2(-4.0, 2.0)) + 317 | getR(vec2(-4.0, 3.0)) + 318 | getR(vec2(-4.0, 4.0)) + 319 | getR(vec2(-3.0, -5.0)) + 320 | getR(vec2(-3.0, -4.0)) + 321 | getR(vec2(-3.0, -3.0)) + 322 | getR(vec2(-3.0, -2.0)) + 323 | getR(vec2(-3.0, 2.0)) + 324 | getR(vec2(-3.0, 3.0)) + 325 | getR(vec2(-3.0, 4.0)) + 326 | getR(vec2(-3.0, 5.0)) + 327 | getR(vec2(-2.0, -5.0)) + 328 | getR(vec2(-2.0, -4.0)) + 329 | getR(vec2(-2.0, -3.0)) + 330 | getR(vec2(-2.0, 3.0)) + 331 | getR(vec2(-2.0, 4.0)) + 332 | getR(vec2(-2.0, 5.0)) + 333 | getR(vec2(-1.0, -6.0)) + 334 | getR(vec2(-1.0, -5.0)) + 335 | getR(vec2(-1.0, -4.0)) + 336 | getR(vec2(-1.0, 4.0)) + 337 | getR(vec2(-1.0, 5.0)) + 338 | getR(vec2(-1.0, 6.0)) + 339 | getR(vec2(0.0, -6.0)) + 340 | getR(vec2(0.0, -5.0)) + 341 | getR(vec2(0.0, -4.0)) + 342 | getR(vec2(0.0, 4.0)) + 343 | getR(vec2(0.0, 5.0)) + 344 | getR(vec2(0.0, 6.0)) + 345 | getR(vec2(1.0, -6.0)) + 346 | getR(vec2(1.0, -5.0)) + 347 | getR(vec2(1.0, -4.0)) + 348 | getR(vec2(1.0, 4.0)) + 349 | getR(vec2(1.0, 5.0)) + 350 | getR(vec2(1.0, 6.0)) + 351 | getR(vec2(2.0, -5.0)) + 352 | getR(vec2(2.0, -4.0)) + 353 | getR(vec2(2.0, -3.0)) + 354 | getR(vec2(2.0, 3.0)) + 355 | getR(vec2(2.0, 4.0)) + 356 | getR(vec2(2.0, 5.0)) + 357 | getR(vec2(3.0, -5.0)) + 358 | getR(vec2(3.0, -4.0)) + 359 | getR(vec2(3.0, -3.0)); 360 | float s6 = 361 | getR(vec2(3.0, -2.0)) + 362 | getR(vec2(3.0, 2.0)) + 363 | getR(vec2(3.0, 3.0)) + 364 | getR(vec2(3.0, 4.0)) + 365 | getR(vec2(3.0, 5.0)) + 366 | getR(vec2(4.0, -4.0)) + 367 | getR(vec2(4.0, -3.0)) + 368 | getR(vec2(4.0, -2.0)) + 369 | getR(vec2(4.0, -1.0)) + 370 | getR(vec2(4.0, 0.0)) + 371 | getR(vec2(4.0, 1.0)) + 372 | getR(vec2(4.0, 2.0)) + 373 | getR(vec2(4.0, 3.0)) + 374 | getR(vec2(4.0, 4.0)) + 375 | getR(vec2(5.0, -3.0)) + 376 | getR(vec2(5.0, -2.0)) + 377 | getR(vec2(5.0, -1.0)) + 378 | getR(vec2(5.0, 0.0)) + 379 | getR(vec2(5.0, 1.0)) + 380 | getR(vec2(5.0, 2.0)) + 381 | getR(vec2(5.0, 3.0)) + 382 | getR(vec2(6.0, -1.0)) + 383 | getR(vec2(6.0, 0.0)) + 384 | getR(vec2(6.0, 1.0)); 385 | float s7 = 386 | getR(vec2(-14.0, -3.0)) + 387 | getR(vec2(-14.0, -2.0)) + 388 | getR(vec2(-14.0, -1.0)) + 389 | getR(vec2(-14.0, 0.0)) + 390 | getR(vec2(-14.0, 1.0)) + 391 | getR(vec2(-14.0, 2.0)) + 392 | getR(vec2(-14.0, 3.0)) + 393 | getR(vec2(-13.0, -6.0)) + 394 | getR(vec2(-13.0, -5.0)) + 395 | getR(vec2(-13.0, -4.0)) + 396 | getR(vec2(-13.0, -3.0)) + 397 | getR(vec2(-13.0, -2.0)) + 398 | getR(vec2(-13.0, -1.0)) + 399 | getR(vec2(-13.0, 0.0)) + 400 | getR(vec2(-13.0, 1.0)) + 401 | getR(vec2(-13.0, 2.0)) + 402 | getR(vec2(-13.0, 3.0)) + 403 | getR(vec2(-13.0, 4.0)) + 404 | getR(vec2(-13.0, 5.0)) + 405 | getR(vec2(-13.0, 6.0)) + 406 | getR(vec2(-12.0, -8.0)) + 407 | getR(vec2(-12.0, -7.0)) + 408 | getR(vec2(-12.0, -6.0)) + 409 | getR(vec2(-12.0, -5.0)) + 410 | getR(vec2(-12.0, -4.0)) + 411 | getR(vec2(-12.0, -3.0)) + 412 | getR(vec2(-12.0, -2.0)) + 413 | getR(vec2(-12.0, -1.0)) + 414 | getR(vec2(-12.0, 0.0)) + 415 | getR(vec2(-12.0, 1.0)) + 416 | getR(vec2(-12.0, 2.0)) + 417 | getR(vec2(-12.0, 3.0)) + 418 | getR(vec2(-12.0, 4.0)) + 419 | getR(vec2(-12.0, 5.0)) + 420 | getR(vec2(-12.0, 6.0)) + 421 | getR(vec2(-12.0, 7.0)) + 422 | getR(vec2(-12.0, 8.0)) + 423 | getR(vec2(-11.0, -9.0)) + 424 | getR(vec2(-11.0, -8.0)) + 425 | getR(vec2(-11.0, -7.0)) + 426 | getR(vec2(-11.0, -6.0)) + 427 | getR(vec2(-11.0, -5.0)) + 428 | getR(vec2(-11.0, -4.0)) + 429 | getR(vec2(-11.0, -3.0)) + 430 | getR(vec2(-11.0, -2.0)) + 431 | getR(vec2(-11.0, -1.0)) + 432 | getR(vec2(-11.0, 0.0)) + 433 | getR(vec2(-11.0, 1.0)) + 434 | getR(vec2(-11.0, 2.0)) + 435 | getR(vec2(-11.0, 3.0)) + 436 | getR(vec2(-11.0, 4.0)) + 437 | getR(vec2(-11.0, 5.0)) + 438 | getR(vec2(-11.0, 6.0)) + 439 | getR(vec2(-11.0, 7.0)) + 440 | getR(vec2(-11.0, 8.0)) + 441 | getR(vec2(-11.0, 9.0)) + 442 | getR(vec2(-10.0, -10.0)) + 443 | getR(vec2(-10.0, -9.0)) + 444 | getR(vec2(-10.0, -8.0)) + 445 | getR(vec2(-10.0, -7.0)); 446 | float s8 = 447 | getR(vec2(-10.0, -6.0)) + 448 | getR(vec2(-10.0, -5.0)) + 449 | getR(vec2(-10.0, 5.0)) + 450 | getR(vec2(-10.0, 6.0)) + 451 | getR(vec2(-10.0, 7.0)) + 452 | getR(vec2(-10.0, 8.0)) + 453 | getR(vec2(-10.0, 9.0)) + 454 | getR(vec2(-10.0, 10.0)) + 455 | getR(vec2(-9.0, -11.0)) + 456 | getR(vec2(-9.0, -10.0)) + 457 | getR(vec2(-9.0, -9.0)) + 458 | getR(vec2(-9.0, -8.0)) + 459 | getR(vec2(-9.0, -7.0)) + 460 | getR(vec2(-9.0, 7.0)) + 461 | getR(vec2(-9.0, 8.0)) + 462 | getR(vec2(-9.0, 9.0)) + 463 | getR(vec2(-9.0, 10.0)) + 464 | getR(vec2(-9.0, 11.0)) + 465 | getR(vec2(-8.0, -12.0)) + 466 | getR(vec2(-8.0, -11.0)) + 467 | getR(vec2(-8.0, -10.0)) + 468 | getR(vec2(-8.0, -9.0)) + 469 | getR(vec2(-8.0, -8.0)) + 470 | getR(vec2(-8.0, 8.0)) + 471 | getR(vec2(-8.0, 9.0)) + 472 | getR(vec2(-8.0, 10.0)) + 473 | getR(vec2(-8.0, 11.0)) + 474 | getR(vec2(-8.0, 12.0)) + 475 | getR(vec2(-7.0, -12.0)) + 476 | getR(vec2(-7.0, -11.0)) + 477 | getR(vec2(-7.0, -10.0)) + 478 | getR(vec2(-7.0, -9.0)) + 479 | getR(vec2(-7.0, -2.0)) + 480 | getR(vec2(-7.0, -1.0)) + 481 | getR(vec2(-7.0, 0.0)) + 482 | getR(vec2(-7.0, 1.0)) + 483 | getR(vec2(-7.0, 2.0)) + 484 | getR(vec2(-7.0, 9.0)) + 485 | getR(vec2(-7.0, 10.0)) + 486 | getR(vec2(-7.0, 11.0)) + 487 | getR(vec2(-7.0, 12.0)) + 488 | getR(vec2(-6.0, -13.0)) + 489 | getR(vec2(-6.0, -12.0)) + 490 | getR(vec2(-6.0, -11.0)) + 491 | getR(vec2(-6.0, -10.0)) + 492 | getR(vec2(-6.0, -4.0)) + 493 | getR(vec2(-6.0, -3.0)) + 494 | getR(vec2(-6.0, 3.0)) + 495 | getR(vec2(-6.0, 4.0)) + 496 | getR(vec2(-6.0, 10.0)) + 497 | getR(vec2(-6.0, 11.0)) + 498 | getR(vec2(-6.0, 12.0)) + 499 | getR(vec2(-6.0, 13.0)) + 500 | getR(vec2(-5.0, -13.0)) + 501 | getR(vec2(-5.0, -12.0)) + 502 | getR(vec2(-5.0, -11.0)) + 503 | getR(vec2(-5.0, -10.0)) + 504 | getR(vec2(-5.0, -5.0)) + 505 | getR(vec2(-5.0, 5.0)) + 506 | getR(vec2(-5.0, 10.0)) + 507 | getR(vec2(-5.0, 11.0)); 508 | float s9 = 509 | getR(vec2(-5.0, 12.0)) + 510 | getR(vec2(-5.0, 13.0)) + 511 | getR(vec2(-4.0, -13.0)) + 512 | getR(vec2(-4.0, -12.0)) + 513 | getR(vec2(-4.0, -11.0)) + 514 | getR(vec2(-4.0, -6.0)) + 515 | getR(vec2(-4.0, -1.0)) + 516 | getR(vec2(-4.0, 0.0)) + 517 | getR(vec2(-4.0, 1.0)) + 518 | getR(vec2(-4.0, 6.0)) + 519 | getR(vec2(-4.0, 11.0)) + 520 | getR(vec2(-4.0, 12.0)) + 521 | getR(vec2(-4.0, 13.0)) + 522 | getR(vec2(-3.0, -14.0)) + 523 | getR(vec2(-3.0, -13.0)) + 524 | getR(vec2(-3.0, -12.0)) + 525 | getR(vec2(-3.0, -11.0)) + 526 | getR(vec2(-3.0, -6.0)) + 527 | getR(vec2(-3.0, -2.0)) + 528 | getR(vec2(-3.0, 2.0)) + 529 | getR(vec2(-3.0, 6.0)) + 530 | getR(vec2(-3.0, 11.0)) + 531 | getR(vec2(-3.0, 12.0)) + 532 | getR(vec2(-3.0, 13.0)) + 533 | getR(vec2(-3.0, 14.0)) + 534 | getR(vec2(-2.0, -14.0)) + 535 | getR(vec2(-2.0, -13.0)) + 536 | getR(vec2(-2.0, -12.0)) + 537 | getR(vec2(-2.0, -11.0)) + 538 | getR(vec2(-2.0, -7.0)) + 539 | getR(vec2(-2.0, -3.0)) + 540 | getR(vec2(-2.0, 3.0)) + 541 | getR(vec2(-2.0, 7.0)) + 542 | getR(vec2(-2.0, 11.0)) + 543 | getR(vec2(-2.0, 12.0)) + 544 | getR(vec2(-2.0, 13.0)) + 545 | getR(vec2(-2.0, 14.0)) + 546 | getR(vec2(-1.0, -14.0)) + 547 | getR(vec2(-1.0, -13.0)) + 548 | getR(vec2(-1.0, -12.0)) + 549 | getR(vec2(-1.0, -11.0)) + 550 | getR(vec2(-1.0, -7.0)) + 551 | getR(vec2(-1.0, -4.0)) + 552 | getR(vec2(-1.0, -1.0)) + 553 | getR(vec2(-1.0, 0.0)) + 554 | getR(vec2(-1.0, 1.0)) + 555 | getR(vec2(-1.0, 4.0)) + 556 | getR(vec2(-1.0, 7.0)) + 557 | getR(vec2(-1.0, 11.0)) + 558 | getR(vec2(-1.0, 12.0)) + 559 | getR(vec2(-1.0, 13.0)) + 560 | getR(vec2(-1.0, 14.0)) + 561 | getR(vec2(0.0, -14.0)) + 562 | getR(vec2(0.0, -13.0)) + 563 | getR(vec2(0.0, -12.0)) + 564 | getR(vec2(0.0, -11.0)) + 565 | getR(vec2(0.0, -7.0)) + 566 | getR(vec2(0.0, -4.0)) + 567 | getR(vec2(0.0, -1.0)) + 568 | getR(vec2(0.0, 1.0)) + 569 | getR(vec2(0.0, 4.0)); 570 | float s10 = 571 | getR(vec2(0.0, 7.0)) + 572 | getR(vec2(0.0, 11.0)) + 573 | getR(vec2(0.0, 12.0)) + 574 | getR(vec2(0.0, 13.0)) + 575 | getR(vec2(0.0, 14.0)) + 576 | getR(vec2(1.0, -14.0)) + 577 | getR(vec2(1.0, -13.0)) + 578 | getR(vec2(1.0, -12.0)) + 579 | getR(vec2(1.0, -11.0)) + 580 | getR(vec2(1.0, -7.0)) + 581 | getR(vec2(1.0, -4.0)) + 582 | getR(vec2(1.0, -1.0)) + 583 | getR(vec2(1.0, 0.0)) + 584 | getR(vec2(1.0, 1.0)) + 585 | getR(vec2(1.0, 4.0)) + 586 | getR(vec2(1.0, 7.0)) + 587 | getR(vec2(1.0, 11.0)) + 588 | getR(vec2(1.0, 12.0)) + 589 | getR(vec2(1.0, 13.0)) + 590 | getR(vec2(1.0, 14.0)) + 591 | getR(vec2(2.0, -14.0)) + 592 | getR(vec2(2.0, -13.0)) + 593 | getR(vec2(2.0, -12.0)) + 594 | getR(vec2(2.0, -11.0)) + 595 | getR(vec2(2.0, -7.0)) + 596 | getR(vec2(2.0, -3.0)) + 597 | getR(vec2(2.0, 3.0)) + 598 | getR(vec2(2.0, 7.0)) + 599 | getR(vec2(2.0, 11.0)) + 600 | getR(vec2(2.0, 12.0)) + 601 | getR(vec2(2.0, 13.0)) + 602 | getR(vec2(2.0, 14.0)) + 603 | getR(vec2(3.0, -14.0)) + 604 | getR(vec2(3.0, -13.0)) + 605 | getR(vec2(3.0, -12.0)) + 606 | getR(vec2(3.0, -11.0)) + 607 | getR(vec2(3.0, -6.0)) + 608 | getR(vec2(3.0, -2.0)) + 609 | getR(vec2(3.0, 2.0)) + 610 | getR(vec2(3.0, 6.0)) + 611 | getR(vec2(3.0, 11.0)) + 612 | getR(vec2(3.0, 12.0)) + 613 | getR(vec2(3.0, 13.0)) + 614 | getR(vec2(3.0, 14.0)) + 615 | getR(vec2(4.0, -13.0)) + 616 | getR(vec2(4.0, -12.0)) + 617 | getR(vec2(4.0, -11.0)) + 618 | getR(vec2(4.0, -6.0)) + 619 | getR(vec2(4.0, -1.0)) + 620 | getR(vec2(4.0, 0.0)) + 621 | getR(vec2(4.0, 1.0)) + 622 | getR(vec2(4.0, 6.0)) + 623 | getR(vec2(4.0, 11.0)) + 624 | getR(vec2(4.0, 12.0)) + 625 | getR(vec2(4.0, 13.0)) + 626 | getR(vec2(5.0, -13.0)) + 627 | getR(vec2(5.0, -12.0)) + 628 | getR(vec2(5.0, -11.0)) + 629 | getR(vec2(5.0, -10.0)) + 630 | getR(vec2(5.0, -5.0)) + 631 | getR(vec2(5.0, 5.0)); 632 | float s11 = 633 | getR(vec2(5.0, 10.0)) + 634 | getR(vec2(5.0, 11.0)) + 635 | getR(vec2(5.0, 12.0)) + 636 | getR(vec2(5.0, 13.0)) + 637 | getR(vec2(6.0, -13.0)) + 638 | getR(vec2(6.0, -12.0)) + 639 | getR(vec2(6.0, -11.0)) + 640 | getR(vec2(6.0, -10.0)) + 641 | getR(vec2(6.0, -4.0)) + 642 | getR(vec2(6.0, -3.0)) + 643 | getR(vec2(6.0, 3.0)) + 644 | getR(vec2(6.0, 4.0)) + 645 | getR(vec2(6.0, 10.0)) + 646 | getR(vec2(6.0, 11.0)) + 647 | getR(vec2(6.0, 12.0)) + 648 | getR(vec2(6.0, 13.0)) + 649 | getR(vec2(7.0, -12.0)) + 650 | getR(vec2(7.0, -11.0)) + 651 | getR(vec2(7.0, -10.0)) + 652 | getR(vec2(7.0, -9.0)) + 653 | getR(vec2(7.0, -2.0)) + 654 | getR(vec2(7.0, -1.0)) + 655 | getR(vec2(7.0, 0.0)) + 656 | getR(vec2(7.0, 1.0)) + 657 | getR(vec2(7.0, 2.0)) + 658 | getR(vec2(7.0, 9.0)) + 659 | getR(vec2(7.0, 10.0)) + 660 | getR(vec2(7.0, 11.0)) + 661 | getR(vec2(7.0, 12.0)) + 662 | getR(vec2(8.0, -12.0)) + 663 | getR(vec2(8.0, -11.0)) + 664 | getR(vec2(8.0, -10.0)) + 665 | getR(vec2(8.0, -9.0)) + 666 | getR(vec2(8.0, -8.0)) + 667 | getR(vec2(8.0, 8.0)) + 668 | getR(vec2(8.0, 9.0)) + 669 | getR(vec2(8.0, 10.0)) + 670 | getR(vec2(8.0, 11.0)) + 671 | getR(vec2(8.0, 12.0)) + 672 | getR(vec2(9.0, -11.0)) + 673 | getR(vec2(9.0, -10.0)) + 674 | getR(vec2(9.0, -9.0)) + 675 | getR(vec2(9.0, -8.0)) + 676 | getR(vec2(9.0, -7.0)) + 677 | getR(vec2(9.0, 7.0)) + 678 | getR(vec2(9.0, 8.0)) + 679 | getR(vec2(9.0, 9.0)) + 680 | getR(vec2(9.0, 10.0)) + 681 | getR(vec2(9.0, 11.0)) + 682 | getR(vec2(10.0, -10.0)) + 683 | getR(vec2(10.0, -9.0)) + 684 | getR(vec2(10.0, -8.0)) + 685 | getR(vec2(10.0, -7.0)) + 686 | getR(vec2(10.0, -6.0)) + 687 | getR(vec2(10.0, -5.0)) + 688 | getR(vec2(10.0, 5.0)) + 689 | getR(vec2(10.0, 6.0)) + 690 | getR(vec2(10.0, 7.0)) + 691 | getR(vec2(10.0, 8.0)) + 692 | getR(vec2(10.0, 9.0)) + 693 | getR(vec2(10.0, 10.0)); 694 | float s12 = 695 | getR(vec2(11.0, -9.0)) + 696 | getR(vec2(11.0, -8.0)) + 697 | getR(vec2(11.0, -7.0)) + 698 | getR(vec2(11.0, -6.0)) + 699 | getR(vec2(11.0, -5.0)) + 700 | getR(vec2(11.0, -4.0)) + 701 | getR(vec2(11.0, -3.0)) + 702 | getR(vec2(11.0, -2.0)) + 703 | getR(vec2(11.0, -1.0)) + 704 | getR(vec2(11.0, 0.0)) + 705 | getR(vec2(11.0, 1.0)) + 706 | getR(vec2(11.0, 2.0)) + 707 | getR(vec2(11.0, 3.0)) + 708 | getR(vec2(11.0, 4.0)) + 709 | getR(vec2(11.0, 5.0)) + 710 | getR(vec2(11.0, 6.0)) + 711 | getR(vec2(11.0, 7.0)) + 712 | getR(vec2(11.0, 8.0)) + 713 | getR(vec2(11.0, 9.0)) + 714 | getR(vec2(12.0, -8.0)) + 715 | getR(vec2(12.0, -7.0)) + 716 | getR(vec2(12.0, -6.0)) + 717 | getR(vec2(12.0, -5.0)) + 718 | getR(vec2(12.0, -4.0)) + 719 | getR(vec2(12.0, -3.0)) + 720 | getR(vec2(12.0, -2.0)) + 721 | getR(vec2(12.0, -1.0)) + 722 | getR(vec2(12.0, 0.0)) + 723 | getR(vec2(12.0, 1.0)) + 724 | getR(vec2(12.0, 2.0)) + 725 | getR(vec2(12.0, 3.0)) + 726 | getR(vec2(12.0, 4.0)) + 727 | getR(vec2(12.0, 5.0)) + 728 | getR(vec2(12.0, 6.0)) + 729 | getR(vec2(12.0, 7.0)) + 730 | getR(vec2(12.0, 8.0)) + 731 | getR(vec2(13.0, -6.0)) + 732 | getR(vec2(13.0, -5.0)) + 733 | getR(vec2(13.0, -4.0)) + 734 | getR(vec2(13.0, -3.0)) + 735 | getR(vec2(13.0, -2.0)) + 736 | getR(vec2(13.0, -1.0)) + 737 | getR(vec2(13.0, 0.0)) + 738 | getR(vec2(13.0, 1.0)) + 739 | getR(vec2(13.0, 2.0)) + 740 | getR(vec2(13.0, 3.0)) + 741 | getR(vec2(13.0, 4.0)) + 742 | getR(vec2(13.0, 5.0)) + 743 | getR(vec2(13.0, 6.0)) + 744 | getR(vec2(14.0, -3.0)) + 745 | getR(vec2(14.0, -2.0)) + 746 | getR(vec2(14.0, -1.0)) + 747 | getR(vec2(14.0, 0.0)) + 748 | getR(vec2(14.0, 1.0)) + 749 | getR(vec2(14.0, 2.0)) + 750 | getR(vec2(14.0, 3.0)); 751 | 752 | //Consolidate the neighbourhood checks 753 | 754 | int sum_0 = int(s0 + s1 + s2 + s3); 755 | int sum_1 = int(s4); 756 | int sum_2 = int(s5 + s6); 757 | int sum_3 = int(s7 + s8 + s9 + s10 + s11 + s12); 758 | 759 | //Apply conditional transition functions 760 | // 761 | // [LIVING]: Red channel = 1.0 762 | // [ DEAD ]: Red channel = 0.0 763 | 764 | if(sum_0 >= 0 && sum_0 <= 17) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } 765 | if(sum_0 >= 40 && sum_0 <= 42) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } 766 | 767 | if(sum_1 >= 10 && sum_1 <= 13) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } 768 | 769 | if(sum_2 >= 9 && sum_2 <= 21) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } 770 | 771 | if(sum_3 >= 78 && sum_3 <= 89) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } 772 | if(sum_3 >= 108) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } 773 | 774 | } 775 | -------------------------------------------------------------------------------- /WebGL-Automata/glsl/BlurFilter.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D tex0_in; 4 | uniform sampler2D tex1_in; 5 | uniform vec2 tex_size; 6 | 7 | float getR(vec2 offset, sampler2D tex) { 8 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).r); 9 | } 10 | 11 | float getG(vec2 offset, sampler2D tex) { 12 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).g); 13 | } 14 | 15 | float getB(vec2 offset, sampler2D tex) { 16 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).b); 17 | } 18 | 19 | 20 | void main() { 21 | 22 | float cR_out = 0.0; 23 | float cG_out = 0.0; 24 | float cB_out = 0.0; 25 | 26 | float cR0 = getR(vec2(0.0, 0.0), tex0_in); 27 | float cG0 = getG(vec2(0.0, 0.0), tex0_in); 28 | float cB0 = getB(vec2(0.0, 0.0), tex0_in); 29 | 30 | float cR1 = getR(vec2(0.0, 0.0), tex1_in); 31 | float cG1 = getG(vec2(0.0, 0.0), tex1_in); 32 | float cB1 = getB(vec2(0.0, 0.0), tex1_in); 33 | 34 | int mode = 2; 35 | 36 | if(mode == 0) { 37 | cR_out = (cR0*0.995 + cR1*0.08) - 0.005; 38 | cG_out = (cG0*0.995 + cG1*0.08) - 0.005; 39 | cB_out = (cB0*0.995 + cB1*0.08) - 0.005; 40 | } 41 | 42 | if(mode == 1) { 43 | float n0r = getR(vec2(-1.0, 0.0), tex1_in); 44 | float n0g = getG(vec2(-1.0, 0.0), tex1_in); 45 | float n0b = getB(vec2(-1.0, 0.0), tex1_in); 46 | 47 | float n1r = getR(vec2(1.0, 0.0), tex1_in); 48 | float n1g = getG(vec2(1.0, 0.0), tex1_in); 49 | float n1b = getB(vec2(1.0, 0.0), tex1_in); 50 | 51 | float n2r = getR(vec2(0.0, -1.0), tex1_in); 52 | float n2g = getG(vec2(0.0, -1.0), tex1_in); 53 | float n2b = getB(vec2(0.0, -1.0), tex1_in); 54 | 55 | float n3r = getR(vec2(0.0, 1.0), tex1_in); 56 | float n3g = getG(vec2(0.0, 1.0), tex1_in); 57 | float n3b = getB(vec2(0.0, 1.0), tex1_in); 58 | 59 | cR_out = (cR0 + ((n0r+n1r+n2r+n3r)/5.0)*0.1) - 0.005; 60 | cG_out = (cG0 + ((n0g+n1g+n2g+n3g)/5.0)*0.1) - 0.005; 61 | cB_out = (cB0 + ((n0b+n1b+n2b+n3b)/5.0)*0.1) - 0.005; 62 | } 63 | 64 | if(mode == 2) { 65 | 66 | float r1 = (getR(vec2(1.0, 0.0), tex0_in) + 67 | getR(vec2(1.0, 1.0), tex0_in) + 68 | getR(vec2(0.0, 1.0), tex0_in) + 69 | getR(vec2(-1.0, 0.0), tex0_in) + 70 | getR(vec2(-1, -1.0), tex0_in) + 71 | getR(vec2(0.0, -1.0), tex0_in) + 72 | getR(vec2(1.0, -1.0), tex0_in) + 73 | getR(vec2(-1.0, 1.0), tex0_in) + 74 | getR(vec2(0.0, 0.0), tex0_in)) / 9.0; 75 | 76 | float g1 = (getG(vec2(1.0, 0.0), tex0_in) + 77 | getG(vec2(1.0, 1.0), tex0_in) + 78 | getG(vec2(0.0, 1.0), tex0_in) + 79 | getG(vec2(-1.0, 0.0), tex0_in) + 80 | getG(vec2(-1.0, -1.0), tex0_in) + 81 | getG(vec2(0.0, -1.0), tex0_in) + 82 | getG(vec2(1.0, -1.0), tex0_in) + 83 | getG(vec2(-1.0, 1.0), tex0_in) + 84 | getG(vec2(0.0, 0.0), tex0_in)) / 9.0; 85 | 86 | float b1 = (getB(vec2(1.0, 0.0), tex0_in) + 87 | getB(vec2(1.0, 1.0), tex0_in) + 88 | getB(vec2(0.0, 1.0), tex0_in) + 89 | getB(vec2(-1.0, 0.0), tex0_in) + 90 | getB(vec2(-1.0, -1.0), tex0_in) + 91 | getB(vec2(0.0, -1.0), tex0_in) + 92 | getB(vec2(1.0, -1.0), tex0_in) + 93 | getB(vec2(-1.0, 1.0), tex0_in) + 94 | getB(vec2(0.0, 0.0), tex0_in)) / 9.0; 95 | 96 | 97 | float r2 = (r1+cR1*0.125); 98 | float g2 = (g1+cG1*0.125); 99 | float b2 = (b1+cB1*0.125); 100 | 101 | float max = 0.7; 102 | 103 | if(r2 > max) {r2 = max;} 104 | if(g2 > max) {g2 = max;} 105 | if(b2 > max) {b2 = max;} 106 | 107 | cR_out = r2 - 0.004; 108 | cG_out = g2 - 0.004; 109 | cB_out = b2 - 0.004; 110 | 111 | } 112 | 113 | gl_FragColor = vec4(cR_out, cG_out, cB_out, 1.0); 114 | 115 | } 116 | 117 | 118 | 119 | /**/ 120 | -------------------------------------------------------------------------------- /WebGL-Automata/glsl/PlaceCirclePierce.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D tex0_in; 4 | uniform sampler2D tex1_in; 5 | uniform vec2 tex_size; 6 | uniform float x; 7 | uniform float y; 8 | uniform float size; 9 | uniform float mode; 10 | 11 | float getR(vec2 offset, sampler2D tex) { 12 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).r); 13 | } 14 | 15 | float getG(vec2 offset, sampler2D tex) { 16 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).g); 17 | } 18 | 19 | float getB(vec2 offset, sampler2D tex) { 20 | return (texture2D(tex, (gl_FragCoord.xy + offset) / tex_size).b); 21 | } 22 | 23 | void main() { 24 | 25 | float R0 = getR(vec2(0.0, 0.0), tex0_in); 26 | float G0 = getG(vec2(0.0, 0.0), tex0_in); 27 | float B0 = getB(vec2(0.0, 0.0), tex0_in); 28 | 29 | float R1 = getR(vec2(0.0, 0.0), tex1_in); 30 | float G1 = getG(vec2(0.0, 0.0), tex1_in); 31 | float B1 = getB(vec2(0.0, 0.0), tex1_in); 32 | 33 | float R = R0; 34 | float G = G0; 35 | float B = B0; 36 | 37 | 38 | float centerx = size / 2.0; 39 | float centery = size / 2.0; 40 | float center_dist = sqrt(((gl_FragCoord.x-(x+centerx))*(gl_FragCoord.x-(x+centerx))) + ((gl_FragCoord.y-(y+centery))*(gl_FragCoord.y-(y+centery)))); 41 | float center_radius = sqrt((centerx*centerx)+(centery*centery)); 42 | 43 | float c_size = size/4.0; 44 | 45 | if(center_dist <= center_radius) { 46 | 47 | if(mode == 1.0 || mode == 3.0) { 48 | float bright = sqrt((c_size/(center_dist))*(c_size/(center_dist))); 49 | 50 | R = (R1 * bright); 51 | G = (G1 * bright); 52 | B = (B1 * bright); 53 | 54 | if(R <= 0.15) {R = 0.0;} 55 | if(G <= 0.15) {G = 0.0;} 56 | if(B <= 0.15) {B = 0.0;}/**/ 57 | 58 | /*float bright = 0.0-(c_size/(center_dist)); 59 | 60 | R = (R * bright)*bright; 61 | G = (G * bright)*bright; 62 | B = (B * bright)*bright; 63 | 64 | if(R <= 0.15) {R = 0.0;} 65 | if(G <= 0.15) {G = 0.0;} 66 | if(B <= 0.15) {B = 0.0;}/**/ 67 | 68 | } 69 | 70 | if(mode == 5.0) { 71 | float bright = 1.0/center_dist; //1.0-1.0/(c_size/(center_dist));// 0.01; 72 | 73 | float R_out = R0+(R1 * bright); 74 | float G_out = G0+(G1 * bright); 75 | float B_out = B0+(B1 * bright); 76 | 77 | if(R1+G1+B1 > 0.0){ 78 | if(R_out > R0) { R = R_out; } 79 | if(G_out > G0) { G = G_out; } 80 | if(B_out > B0) { B = B_out; } 81 | } 82 | 83 | } 84 | 85 | if(mode == 4.0) { 86 | float bright = 1.0/center_dist; //1.0-1.0/(c_size/(center_dist));// 0.01; 87 | 88 | float R_out = R0-(R1 * bright); 89 | float G_out = G0-(G1 * bright); 90 | float B_out = B0-(B1 * bright); 91 | 92 | if(R1+G1+B1 > 0.0){ 93 | if(R_out < R0) { R = R_out; } 94 | if(G_out < G0) { G = G_out; } 95 | if(B_out < B0) { B = B_out; } 96 | } 97 | } 98 | 99 | if(mode == 6.0) { 100 | float bright = 1.0-1.0/(c_size/(center_dist));// 101 | 102 | float R_out = R0+(R1 * bright); 103 | float G_out = G0+(G1 * bright); 104 | float B_out = B0+(B1 * bright); 105 | 106 | if(R1+G1+B1 > 0.0){ 107 | if(R_out > R0) { R = R_out; } 108 | if(G_out > G0) { G = G_out; } 109 | if(B_out > B0) { B = B_out; } 110 | } 111 | 112 | } 113 | 114 | if(mode == 7.0) { 115 | float bright = 1.0-1.0/(c_size/(center_dist));// 1.0/center_dist; 116 | 117 | float R_out = R0-(R1 * bright); 118 | float G_out = G0-(G1 * bright); 119 | float B_out = B0-(B1 * bright); 120 | 121 | if(R1+G1+B1 > 0.0){ 122 | if(R_out < R0) { R = R_out; } 123 | if(G_out < G0) { G = G_out; } 124 | if(B_out < B0) { B = B_out; } 125 | } 126 | } 127 | 128 | if(mode == 2.0 || mode == 3.0) { 129 | 130 | if(R > 0.15) { R = 1.0; } else {R = getR(vec2(0.0, 0.0), tex0_in);} 131 | if(G > 0.15) { G = 1.0; } else {G = getG(vec2(0.0, 0.0), tex0_in);} 132 | if(B > 0.15) { B = 1.0; } else {B = getB(vec2(0.0, 0.0), tex0_in);} 133 | 134 | //B=G=R; 135 | } 136 | 137 | } 138 | 139 | 140 | 141 | 142 | 143 | gl_FragColor = vec4(R, G, B, 1.0); 144 | } 145 | -------------------------------------------------------------------------------- /WebGL-Automata/glsl/TexMerge.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D tex0_in; 4 | uniform sampler2D tex1_in; 5 | uniform vec2 tex_size; 6 | 7 | float get_col_sum(sampler2D tex) { 8 | return 9 | texture2D(tex, (gl_FragCoord.xy) / tex_size).r + 10 | texture2D(tex, (gl_FragCoord.xy) / tex_size).g + 11 | texture2D(tex, (gl_FragCoord.xy) / tex_size).b; 12 | } 13 | 14 | void main() { 15 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 16 | if(get_col_sum(tex1_in) > 0.0) { gl_FragColor = texture2D(tex1_in, gl_FragCoord.xy / tex_size); } 17 | if(get_col_sum(tex0_in) > 0.0) { gl_FragColor = texture2D(tex0_in, gl_FragCoord.xy / tex_size); } 18 | } 19 | -------------------------------------------------------------------------------- /WebGL-Automata/glsl/copy.frag: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | uniform sampler2D tex0_in; 4 | uniform vec2 tex_size; 5 | uniform float scale; 6 | 7 | void main() { 8 | 9 | gl_FragColor = texture2D(tex0_in, gl_FragCoord.xy / (tex_size*scale)); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /WebGL-Automata/glsl/quad.vert: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | attribute vec2 quad; 4 | 5 | void main() { 6 | gl_Position = vec4(quad, 0, 1.0); 7 | } 8 | -------------------------------------------------------------------------------- /WebGL-Automata/gol.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 16px auto; 3 | // width: 1024px; 4 | background: #303030; 5 | font-family: sans-serif; 6 | user-select: none; 7 | -moz-user-select: none; 8 | -webkit-user-select: none; 9 | -webkit-touch-callout: none; 10 | 11 | } 12 | 13 | h1 { 14 | color: White; 15 | text-align: Left; 16 | margin: 0; 17 | } 18 | 19 | 20 | canvas#life { 21 | border: 3px solid #333; 22 | -moz-transform:scale(1,-1); 23 | position:absolute; 24 | left:64px; 25 | top:64px; 26 | } 27 | 28 | canvas#gc { 29 | border: 3px solid #333; 30 | position:absolute; 31 | left:64px; 32 | top:64px; 33 | } 34 | 35 | .fps { 36 | position: absolute; 37 | top: 0; 38 | right: 512ddd; 39 | color: White; 40 | font-size: 18px; 41 | } 42 | -------------------------------------------------------------------------------- /WebGL-Automata/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WebGL CA 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

WebGL Cellular Automata

17 | 18 | 19 |
20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /WebGL-Automata/js/gol.js: -------------------------------------------------------------------------------- 1 | function GOL(canvas) { 2 | 3 | // Core Engine 4 | var igloo = this.igloo = new Igloo(canvas, { preserveDrawingBuffer: true }); 5 | var gl = igloo.gl; 6 | if (gl == null) { 7 | alert('Could not initialize WebGL!'); 8 | throw new Error('No WebGL'); 9 | } 10 | 11 | //Initial Dimensions 12 | this.S = 1; //Scale (n^2 only) 13 | var w = canvas.width, h = canvas.height; 14 | this.canvas = canvas; 15 | this.statesize = new Float32Array([w/this.S, h/this.S]); 16 | this.RATIO_DIV = this.statesize[0]/this.statesize[1]; 17 | 18 | //Main Loop Timer 19 | this.timer = null; 20 | this.lasttick = GOL.now(); 21 | this.fps = 0; //fps counter 22 | 23 | //Performance Controls 24 | this.gpuframes = 1; //GPU frames to compute before rendering 25 | this.fps_target = 33.3; //Determines framerate. 66.6 = 15fps, 33.3 = 30fps, 16.7 = 60fps 26 | 27 | //Hide the mouse 28 | document.getElementById("life").style.cursor = "none"; 29 | 30 | this.allframecount = 0; //Used to pause after first frame is loaded & rendered 31 | 32 | /* ******************* Initial state setup ******************* */ 33 | 34 | this.useMouse = true; 35 | this.usefilter = false; 36 | 37 | //Recording Functions 38 | this.recordnow = false; 39 | this.capture_frame_mod = 4; 40 | this.export_image = null; 41 | this.export_images = new Array(); 42 | this.gen = 0; 43 | this.render_frame = 0; 44 | 45 | /* *********************************************************** */ 46 | 47 | //Load the shaders 48 | this.rule_paths = new Array(); 49 | this.rule_paths.push('glsl/0.frag'); 50 | this.rule_paths.push('glsl/BlurFilter.frag'); 51 | 52 | //Define the collection of shaders 53 | this.programs = { 54 | 55 | Rule0: igloo.program('glsl/quad.vert', this.rule_paths[0]), 56 | blurFilter: igloo.program('glsl/quad.vert', this.rule_paths[1]), 57 | 58 | //Utility shaders 59 | copy: igloo.program('glsl/quad.vert', 'glsl/copy.frag'), 60 | merge: igloo.program('glsl/quad.vert', 'glsl/TexMerge.frag'), 61 | place_circle_pierce: igloo.program('glsl/quad.vert', 'glsl/PlaceCirclePierce.frag') 62 | }; 63 | 64 | //Rule & seed selection containers 65 | this.rule_array = new Array(2); 66 | this.rule_array[0] = this.programs.Rule0; 67 | this.rule_array[1] = this.programs.blurFilter; 68 | 69 | 70 | 71 | 72 | //Create the quad that displays the texture 73 | this.buffers = { 74 | quad: igloo.array(Igloo.QUAD2) 75 | }; 76 | 77 | //Define the textures to be used 78 | this.textures = { 79 | layer0_0: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 80 | .blank(this.statesize[0], this.statesize[1]), 81 | layer0_1: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 82 | .blank(this.statesize[0], this.statesize[1]), 83 | 84 | filter0_0: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 85 | .blank(this.statesize[0], this.statesize[1]), 86 | filter0_1: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 87 | .blank(this.statesize[0], this.statesize[1]), 88 | 89 | render0: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 90 | .blank(this.statesize[0], this.statesize[1]), 91 | 92 | capture0: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 93 | .blank(this.statesize[0]*this.S, this.statesize[1]*this.S), 94 | 95 | rand0: igloo.texture(null, gl.RGBA, gl.REPEAT, gl.NEAREST) 96 | .blank(this.statesize[0], this.statesize[1]) 97 | 98 | }; 99 | 100 | //Bind textures to this so they can be drawn to 101 | this.framebuffers = { 102 | step: igloo.framebuffer() 103 | }; 104 | 105 | // ************************************ 106 | // ********** Game Additions ********** 107 | // ************************************ 108 | 109 | //Game canvas layer 110 | this.gc = document.createElement("canvas"); 111 | this.gc.id = "gc"; 112 | this.gc.width = this.canvas.width; 113 | this.gc.height = this.canvas.height; 114 | this.gc_ctx = this.gc.getContext("2d"); 115 | document.body.appendChild(this.gc); 116 | 117 | //Game Initial Setup 118 | this.game_frame = 0; //for timing of second layer, relative to the first 119 | 120 | this.seedStrength = 0.25; 121 | this.seedMode = 1; 122 | this.setRandom(this.textures.layer0_0, this.seedStrength, this.seedMode); 123 | this.setRandom(this.textures.rand0, this.seedStrength, this.seedMode); 124 | 125 | //Mouse tracking 126 | this.mouse = [0,0]; 127 | 128 | } 129 | 130 | 131 | 132 | 133 | /* ************************ 134 | // GPU functions // 135 | ************************ */ 136 | 137 | GOL.prototype.setEmpty = function(tex) { 138 | var rgba = new Uint8Array(this.statesize[0] * this.statesize[1] * 4); 139 | for (var i = 0; i < this.statesize[0]*this.statesize[1]; i++) { 140 | var ii = i * 4; 141 | rgba[ii + 0] = rgba[ii + 1] = rgba[ii + 2] = 0; 142 | rgba[ii + 3] = 255; 143 | } 144 | tex.subset(rgba, 0, 0, this.statesize[0], this.statesize[1]); 145 | return this; 146 | }; 147 | 148 | GOL.prototype.setRandom = function(tex, p, mode) { 149 | 150 | //Mode 0: Binary Mixed 151 | //Mode 1: Binary Mono 152 | //Mode 2: Gradient Mixed Gamma 153 | //Mode 3: Gradient Mixed 154 | //Mode 4: Binary Red 155 | //Mode 5: Binary Red Green 156 | 157 | 158 | var gl = this.igloo.gl 159 | var size = this.statesize[0] * this.statesize[1]; 160 | 161 | var randR = new Uint8Array(size); 162 | var randG = new Uint8Array(size); 163 | var randB = new Uint8Array(size); 164 | 165 | if(mode == 0) { 166 | for (var i = 0; i < size; i++) { 167 | randR[i] = Math.random() < p ? 1 : 0; 168 | } 169 | 170 | for (var i = 0; i < size; i++) { 171 | randG[i] = Math.random() < p ? 1 : 0; 172 | } 173 | 174 | for (var i = 0; i < size; i++) { 175 | randB[i] = Math.random() < p ? 1 : 0; 176 | } 177 | this.setChans(tex, randR, randG, randB); 178 | } 179 | 180 | if(mode == 1) { 181 | for (var i = 0; i < size; i++) { 182 | randR[i] = randG[i] = randB[i] = Math.random() < p ? 1 : 0; 183 | } 184 | this.setChans(tex, randR, randG, randB); 185 | } 186 | 187 | if(mode == 2) { 188 | for (var i = 0; i < size; i++) { 189 | randR[i] = Math.random()*255*p; 190 | } 191 | 192 | for (var i = 0; i < size; i++) { 193 | randG[i] = Math.random()*255*p; 194 | } 195 | 196 | for (var i = 0; i < size; i++) { 197 | randB[i] = Math.random()*255*p; 198 | } 199 | this.setChansImg(randR, randG, randB, tex); 200 | } 201 | 202 | if(mode == 3) { 203 | for (var i = 0; i < size; i++) { 204 | if(Math.random() < p) {randR[i] = Math.random()*255;} 205 | } 206 | 207 | for (var i = 0; i < size; i++) { 208 | if(Math.random() < p) {randG[i] = Math.random()*255;} 209 | } 210 | 211 | for (var i = 0; i < size; i++) { 212 | if(Math.random() < p) {randB[i] = Math.random()*255;} 213 | } 214 | this.setChansImg(randR, randG, randB, tex); 215 | } 216 | 217 | if(mode == 4) { 218 | for (var i = 0; i < size; i++) { 219 | randR[i] = Math.random() < p ? 1 : 0; 220 | } 221 | 222 | for (var i = 0; i < size; i++) { 223 | randG[i] = 0; 224 | } 225 | 226 | for (var i = 0; i < size; i++) { 227 | randB[i] = 0; 228 | } 229 | this.setChans(tex, randR, randG, randB); 230 | } 231 | 232 | if(mode == 5) { 233 | for (var i = 0; i < size; i++) { 234 | randR[i] = Math.random() < p ? 1 : 0; 235 | } 236 | 237 | for (var i = 0; i < size; i++) { 238 | randG[i] = Math.random() < p ? 1 : 0; 239 | } 240 | 241 | for (var i = 0; i < size; i++) { 242 | randB[i] = 0; 243 | } 244 | this.setChans(tex, randR, randG, randB); 245 | } 246 | 247 | return this; 248 | }; 249 | 250 | GOL.prototype.setChans = function(tex, stateR, stateG, stateB) { 251 | var rgba = new Uint8Array(this.statesize[0] * this.statesize[1] * 4); 252 | for (var i = 0; i < stateR.length; i++) { 253 | var ii = i * 4; 254 | 255 | rgba[ii + 0] = stateR[i] ? 255 : 0; 256 | rgba[ii + 1] = stateG[i] ? 255 : 0; 257 | rgba[ii + 2] = stateB[i] ? 255 : 0; 258 | 259 | rgba[ii + 3] = 255; 260 | } 261 | tex.subset(rgba, 0, 0, this.statesize[0], this.statesize[1]); 262 | return this; 263 | }; 264 | 265 | GOL.prototype.swap = function(layer) { 266 | 267 | if(layer == 0) { 268 | var tmp = this.textures.layer0_0; 269 | this.textures.layer0_0 = this.textures.layer0_1; 270 | this.textures.layer0_1 = tmp; 271 | } 272 | 273 | if(layer == 1) { 274 | var tmp = this.textures.filter0_0; 275 | this.textures.filter0_0 = this.textures.filter0_1; 276 | this.textures.filter0_1 = tmp; 277 | } 278 | 279 | return this; 280 | }; 281 | 282 | GOL.prototype.step = function(out, in0, in1, rule_prog, layer, x, y, w, h) { 283 | var gl = this.igloo.gl; 284 | this.framebuffers.step.attach(out); 285 | in0.bind(0); 286 | in1.bind(1); 287 | rule_prog.use() 288 | .attrib('quad', this.buffers.quad, 2) 289 | .uniformi('tex0_in', 0) 290 | .uniformi('tex1_in', 1) 291 | .uniform('tex_size', this.statesize) 292 | .draw(gl.TRIANGLE_STRIP, 4); 293 | this.swap(layer); 294 | return this; 295 | }; 296 | 297 | GOL.prototype.merge = function(out, in0, in1, in2, in3) { 298 | var gl = this.igloo.gl; 299 | this.framebuffers.step.attach(out); 300 | in0.bind(0); 301 | in1.bind(1); 302 | this.programs.merge.use() 303 | .attrib('quad', this.buffers.quad, 2) 304 | .uniformi('tex0_in', 0) 305 | .uniformi('tex1_in', 1) 306 | .uniform('tex_size', this.statesize) 307 | .draw(gl.TRIANGLE_STRIP, 4); 308 | 309 | return this; 310 | }; 311 | 312 | GOL.prototype.draw = function() { 313 | var gl = this.igloo.gl; 314 | this.igloo.defaultFramebuffer.bind(); 315 | this.textures.render0.bind(0); 316 | gl.viewport(0, 0, this.statesize[0]*this.S, this.statesize[1]*this.S); 317 | this.programs.copy.use() 318 | .attrib('quad', this.buffers.quad, 2) 319 | .uniformi('tex0_in', 0) 320 | .uniform('tex_size', this.statesize) 321 | .uniform('scale', this.S) 322 | .draw(gl.TRIANGLE_STRIP, 4); 323 | return this; 324 | }; 325 | 326 | GOL.prototype.capture = function(out, in0) { 327 | var gl = this.igloo.gl; 328 | this.framebuffers.step.attach(out); 329 | in0.bind(0); 330 | this.programs.copy.use() 331 | .attrib('quad', this.buffers.quad, 2) 332 | .uniformi('tex0_in', 0) 333 | .uniform('tex_size', this.statesize) 334 | .uniform('scale', this.S) 335 | .draw(gl.TRIANGLE_STRIP, 4); 336 | 337 | return this; 338 | }; 339 | 340 | GOL.prototype.place_circle_pierce = function(tex0, tex1, tex2, x, y, size, layer, mode) { 341 | var gl = this.igloo.gl; 342 | this.framebuffers.step.attach(tex2); 343 | tex0.bind(0); 344 | tex1.bind(1); 345 | this.programs.place_circle_pierce.use() 346 | .attrib('quad', this.buffers.quad, 2) 347 | .uniformi('tex0_in', 0) 348 | .uniformi('tex1_in', 1) 349 | .uniform('tex_size', this.statesize) 350 | .uniform('x', x - size/2) 351 | .uniform('y', y - size/2) 352 | .uniform('size', size) 353 | .uniform('mode', mode) 354 | .draw(gl.TRIANGLE_STRIP, 4); 355 | this.swap(layer); 356 | return this; 357 | }; 358 | 359 | 360 | /* ************************ 361 | // End GPU functions // 362 | ************************ */ 363 | 364 | 365 | // --------------------------------------- 366 | 367 | 368 | /* ************************ 369 | // MAIN LOOP // 370 | ************************ */ 371 | GOL.prototype.start = function(canvas) { 372 | if (this.timer == null) { 373 | this.timer = setInterval(function(){ 374 | 375 | //Once a second, refresh the FPS counter (and temporarily game score) 376 | if (GOL.now() != this.lasttick) { 377 | $('.fps').text(this.fps + ' FPS'); 378 | this.lasttick = GOL.now(); 379 | this.fps = 0; 380 | } else { 381 | this.fps++; 382 | } 383 | 384 | //Compute the next frame(s) of the CA 385 | for (var repeat_frame_i = 0; repeat_frame_i < gol.gpuframes; repeat_frame_i++) { 386 | 387 | 388 | // *** process layer 0 *** 389 | gol.step( 390 | gol.textures.layer0_1, gol.textures.layer0_0, gol.textures.rand0, gol.rule_array[0], 0, 391 | gol.statesize[0]/2, gol.statesize[1]/2, 392 | gol.statesize[0]/4, gol.statesize[1]/4 393 | ); 394 | 395 | // *** process Filter *** 396 | if(gol.usefilter){ 397 | gol.step( 398 | gol.textures.filter0_1, gol.textures.filter0_0, gol.textures.layer0_0, gol.rule_array[1], 1, 399 | gol.statesize[0]/2, gol.statesize[1]/2, 400 | gol.statesize[0]/4, gol.statesize[1]/4 401 | ); 402 | } 403 | 404 | //player mouse seeder 405 | if(gol.useMouse) {gol.place_circle_pierce(gol.textures.layer0_0, gol.textures.rand0, gol.textures.layer0_1, gol.mouse[0], gol.mouse[1], 16, 0, 3);} 406 | 407 | 408 | gol.game_frame++; 409 | } 410 | 411 | //Merge the generated textures 412 | gol.merge( 413 | gol.textures.render0, 414 | gol.textures.layer0_0, 415 | gol.textures.filter0_0 416 | ); 417 | 418 | //Render the final texture to the screen 419 | gol.draw(); 420 | 421 | //pause on loading, after the first frame is drawn 422 | if(gol.allframecount == 1) {gol.toggle();} 423 | 424 | //Count the total number of displayed/rendered frames 425 | gol.allframecount++; 426 | 427 | 428 | 429 | //Image Export handler 430 | if (gol.recordnow === true) { 431 | 432 | gol.gen += 1; 433 | if(gol.gen % gol.capture_frame_mod === 0/*(gol.gen > 600 && gol.gen % 100 === 0) || (gol.gen < 600 && gol.gen % 10 === 0) || (gol.gen < 30)*/){ 434 | 435 | var rendmod = 100; 436 | 437 | gol.capture( 438 | gol.textures.capture0, 439 | gol.textures.render0 440 | ); 441 | 442 | gol.export_image = gol.exportImage(gol.igloo.gl, gol.textures.capture0.texture, gol.canvas.width, gol.canvas.height); 443 | gol.export_images[gol.render_frame%rendmod] = gol.export_image; 444 | gol.render_frame += 1; 445 | 446 | 447 | if(gol.render_frame % rendmod === 0) { 448 | gol.downloadAll(gol.export_images, gol.render_frame-rendmod); 449 | } 450 | } 451 | } 452 | 453 | }, this.fps_target); //Determines framerate. 66.6 = 15fps, 33.3 = 30fps, 16.7 = 60fps 454 | 455 | } 456 | return this; 457 | }; 458 | 459 | 460 | // --------------------------------------- 461 | 462 | /* ************************ 463 | // General functions // 464 | ************************ */ 465 | 466 | GOL.now = function() { 467 | return Math.floor(Date.now() / 1000); 468 | }; 469 | 470 | GOL.prototype.stop = function() { 471 | clearInterval(this.timer); 472 | this.timer = null; 473 | return this; 474 | }; 475 | 476 | GOL.prototype.toggle = function() { 477 | if (this.timer == null) { 478 | this.start(); 479 | } else { 480 | this.stop(); 481 | } 482 | }; 483 | 484 | GOL.prototype.exportImage = function(gl, texture, width, height) { 485 | 486 | // Create a framebuffer backed by the texture 487 | var framebuffer = gl.createFramebuffer(); 488 | gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); 489 | gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); 490 | 491 | // Read the contents of the framebuffer 492 | var data = new Uint8Array(width * height * 4); 493 | gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data); 494 | 495 | gl.deleteFramebuffer(framebuffer); 496 | 497 | // Create a 2D canvas to store the result 498 | var canvas = document.createElement('canvas'); 499 | canvas.width = width; 500 | canvas.height = height; 501 | var context = canvas.getContext('2d'); 502 | 503 | // Copy the pixels to a 2D canvas 504 | var imageData = context.createImageData(width, height); 505 | imageData.data.set(data); 506 | context.putImageData(imageData, 0, 0); 507 | 508 | var img = new Image(); 509 | img.src = canvas.toDataURL("image/png"); 510 | 511 | return img; 512 | }; 513 | 514 | //Export saved PNG images to a new tab for viewing. 515 | GOL.prototype.imageDump = function() { 516 | 517 | //Write a html document containing the images 518 | var s = ""; 519 | for (var i = 0; i < gol.export_images.length; i++) { 520 | s = s + ''; 521 | } 522 | 523 | //open a new tab and display the images 524 | var newWindow = window.open(); 525 | newWindow.document.write(s); 526 | newWindow.document.close(); 527 | 528 | //Clear the images from memory 529 | gol.export_images = []; 530 | 531 | }; 532 | 533 | /* Download an img */ 534 | GOL.prototype.download = function(img, imgnum) { 535 | var zerStr = ""; 536 | for (i = 0; i < 6-imgnum.toString().length; i++) { 537 | zerStr += "0"; 538 | } 539 | zerStr+=imgnum.toString(); 540 | 541 | var link = document.createElement("a"); 542 | link.href = img.src; 543 | link.download = "image" + zerStr + ".png"; 544 | link.style.display = "none"; 545 | var evt = new MouseEvent("click", { 546 | "view": window, 547 | "bubbles": true, 548 | "cancelable": true 549 | }); 550 | 551 | document.body.appendChild(link); 552 | link.dispatchEvent(evt); 553 | document.body.removeChild(link); 554 | //console.log("Downloading..."); 555 | } 556 | 557 | /* Download all images in 'imgs'. 558 | * Optionaly filter them by extension (e.g. "jpg") and/or 559 | * download the 'limit' first only */ 560 | GOL.prototype.downloadAll = function(imgs, imgnum) { 561 | 562 | /* (Try to) download the images */ 563 | for (var i = 0; i < imgs.length; i++) { 564 | gol.download(imgs[i], imgnum+i); 565 | } 566 | 567 | } 568 | 569 | 570 | /** 571 | * Find simulation coordinates for event. 572 | * This is a workaround for Firefox bug #69787 and jQuery bug #8523. 573 | * @returns {Array} target-relative offset 574 | */ 575 | GOL.prototype.eventCoord = function(event) { 576 | var $target = $(event.target), 577 | offset = $target.offset(), 578 | border = 1, 579 | x = event.pageX - offset.left - border, 580 | y = $target.height() - (event.pageY - offset.top - border); 581 | return [Math.floor(x), Math.floor(y)]; 582 | }; 583 | 584 | 585 | 586 | //Builds the menu & event handlers 587 | function addGUI() { 588 | var gui = new dat.GUI(), 589 | cont = new myConfig(); 590 | gui.cont = cont; 591 | 592 | // *********************************************** 593 | 594 | gui.add(cont, 'bPause') .name('Pause').onFinishChange(tog); 595 | gui.add(cont, 'bMouse') .name('Mouse Seeding').onFinishChange(mouse); 596 | gui.add(cont, 'bFilter') .name('Apply Filter').onFinishChange(tog_filter); 597 | gui.add(cont, 'bRecord') .name('Record Frames').onFinishChange(tog_record); 598 | 599 | 600 | gui.add(cont, 'fps', 1, 60) .step(1.0).name('Target FPS').onFinishChange(set_fps); 601 | gui.add(cont, 'gpuframes', 1, 32) .step(1.0).name('GPU Frames').onFinishChange(set_gpuframes); 602 | gui.add(cont, 'reseed', 0, 1) .step(0.01).name('Reseed Strength').onFinishChange(set_reseed); 603 | gui.add(cont, 'recframerate', 1, 1024) .step(1.0).name('Record Frame-skip').onFinishChange(set_frame_capture); 604 | //gui.add(cont, 'seedmode', 0, 5) .step(1).name('Seed Mode').onFinishChange(set_seedmode); 605 | 606 | // *********************************************** 607 | 608 | function tog(){ 609 | gol.toggle(); 610 | document.getElementById("life").focus(); 611 | } 612 | 613 | function mouse(){ 614 | gol.useMouse = !gol.useMouse; 615 | document.getElementById("life").focus(); 616 | } 617 | 618 | function tog_record(value){ 619 | gol.recordnow = !gol.recordnow; 620 | document.getElementById("life").focus(); 621 | } 622 | 623 | function tog_filter(value){ 624 | gol.usefilter = !gol.usefilter; 625 | gol.setEmpty(gol.textures.filter0_0); 626 | document.getElementById("life").focus(); 627 | } 628 | 629 | function set_frame_capture(value){ 630 | gol.capture_frame_mod = value; 631 | } 632 | 633 | function set_fps(value){ 634 | gol.toggle(); 635 | gol.fps_target = 1000/value; 636 | gol.toggle(); 637 | document.getElementById("life").focus(); 638 | } 639 | 640 | function set_gpuframes(value){ 641 | gol.toggle(); 642 | gol.gpuframes = Math.round(value); 643 | gol.toggle(); 644 | document.getElementById("life").focus(); 645 | } 646 | 647 | function set_reseed(value){ 648 | gol.toggle(); 649 | gol.seedStrength = value; 650 | gol.setRandom(gol.textures.layer0_0, gol.seedStrength, gol.seedMode); 651 | gol.setRandom(gol.textures.rand0, gol.seedStrength, gol.seedMode); 652 | //gol.reset_rules(0); 653 | gol.toggle(); 654 | document.getElementById("life").focus(); 655 | } 656 | 657 | 658 | function set_seedmode(value){ 659 | gol.seedMode = value; 660 | document.getElementById("life").focus(); 661 | } 662 | 663 | 664 | // *********************************************** 665 | 666 | return gui; 667 | 668 | } 669 | 670 | function myConfig() { 671 | this.bPause = true; 672 | this.bMouse = gol.useMouse; 673 | this.bFilter = gol.usefilter; 674 | this.bRecord = gol.recordnow; 675 | this.recframerate = gol.capture_frame_mod; 676 | this.fps = 30; 677 | this.gpuframes = gol.gpuframes; 678 | this.reseed = gol.seedStrength; 679 | this.seedmode = gol.seedMode; 680 | } 681 | 682 | function Controller(gol) { 683 | this.gol = gol; 684 | var _this = this; 685 | var $canvas = $(gol.igloo.canvas); 686 | var $canvas_gc = $(gol.gc); 687 | 688 | gol.gui = addGUI(); 689 | 690 | //Prevent default actions like right-click menus 691 | $canvas_gc.on('contextmenu', function(event) { 692 | event.preventDefault(); 693 | return false; 694 | }); 695 | 696 | $canvas_gc.on('mousemove', function(event) { 697 | var pos = gol.eventCoord(event); 698 | gol.mouse[0] = pos[0]/(gol.S); 699 | gol.mouse[1] = ((gol.statesize[1])-pos[1]/gol.S); 700 | }); 701 | } 702 | 703 | GOL.prototype.reset_rules = function() { 704 | 705 | gol.programs = { 706 | Rule0: gol.igloo.program('glsl/quad.vert', gol.rule_paths[0]), 707 | blurFilter: igloo.program('glsl/quad.vert', gol.rule_paths[1]), 708 | 709 | //Utility shaders 710 | copy: gol.igloo.program('glsl/quad.vert', 'glsl/copy.frag'), 711 | merge: gol.igloo.program('glsl/quad.vert', 'glsl/TexMerge.frag'), 712 | place_circle_pierce: gol.igloo.program('glsl/quad.vert', 'glsl/PlaceCirclePierce.frag') 713 | }; 714 | 715 | gol.rule_array[0] = gol.programs.Rule0; 716 | gol.rule_array[1] = gol.programs.blurFilter; 717 | } 718 | 719 | 720 | /* ************************ 721 | // End General functions // 722 | ************************ */ 723 | 724 | 725 | // Initialize everything. Entry Point. 726 | var gol = null, controller = null, player = null; 727 | $(document).ready(function() { 728 | var $canvas = $('#life'); 729 | gol = new GOL($canvas[0]).draw().start($canvas[0]); 730 | controller = new Controller(gol); //GUI 731 | }); 732 | 733 | //Don't scroll on spacebar 734 | $(window).on('keydown', function(event) { 735 | return !(event.keyCode === 32); 736 | }); 737 | 738 | -------------------------------------------------------------------------------- /WebGL-Automata/js/vendor/dat.gui.min.js: -------------------------------------------------------------------------------- 1 | var dat=dat||{};dat.gui=dat.gui||{};dat.utils=dat.utils||{};dat.controllers=dat.controllers||{};dat.dom=dat.dom||{};dat.color=dat.color||{};dat.utils.css=function(){return{load:function(f,a){a=a||document;var d=a.createElement("link");d.type="text/css";d.rel="stylesheet";d.href=f;a.getElementsByTagName("head")[0].appendChild(d)},inject:function(f,a){a=a||document;var d=document.createElement("style");d.type="text/css";d.innerHTML=f;a.getElementsByTagName("head")[0].appendChild(d)}}}(); 2 | dat.utils.common=function(){var f=Array.prototype.forEach,a=Array.prototype.slice;return{BREAK:{},extend:function(d){this.each(a.call(arguments,1),function(a){for(var c in a)this.isUndefined(a[c])||(d[c]=a[c])},this);return d},defaults:function(d){this.each(a.call(arguments,1),function(a){for(var c in a)this.isUndefined(d[c])&&(d[c]=a[c])},this);return d},compose:function(){var d=a.call(arguments);return function(){for(var e=a.call(arguments),c=d.length-1;0<=c;c--)e=[d[c].apply(this,e)];return e[0]}}, 3 | each:function(a,e,c){if(a)if(f&&a.forEach&&a.forEach===f)a.forEach(e,c);else if(a.length===a.length+0)for(var b=0,q=a.length;bthis.__max&&(a=this.__max);void 0!==this.__step&&0!=a%this.__step&&(a=Math.round(a/this.__step)*this.__step);return e.superclass.prototype.setValue.call(this,a)},min:function(a){this.__min=a;return this},max:function(a){this.__max=a;return this},step:function(a){this.__impliedStep=this.__step=a;this.__precision=d(a);return this}});return e}(dat.controllers.Controller,dat.utils.common); 17 | dat.controllers.NumberControllerBox=function(f,a,d){var e=function(c,b,f){function r(){var a=parseFloat(n.__input.value);d.isNaN(a)||n.setValue(a)}function m(a){var b=p-a.clientY;n.setValue(n.getValue()+b*n.__impliedStep);p=a.clientY}function s(){a.unbind(window,"mousemove",m);a.unbind(window,"mouseup",s)}this.__truncationSuspended=!1;e.superclass.call(this,c,b,f);var n=this,p;this.__input=document.createElement("input");this.__input.setAttribute("type","text");a.bind(this.__input,"change",r);a.bind(this.__input, 18 | "blur",function(){r();n.__onFinishChange&&n.__onFinishChange.call(n,n.getValue())});a.bind(this.__input,"mousedown",function(b){a.bind(window,"mousemove",m);a.bind(window,"mouseup",s);p=b.clientY});a.bind(this.__input,"keydown",function(a){13===a.keyCode&&(n.__truncationSuspended=!0,this.blur(),n.__truncationSuspended=!1)});this.updateDisplay();this.domElement.appendChild(this.__input)};e.superclass=f;d.extend(e.prototype,f.prototype,{updateDisplay:function(){var a=this.__input,b;if(this.__truncationSuspended)b= 19 | this.getValue();else{b=this.getValue();var d=Math.pow(10,this.__precision);b=Math.round(b*d)/d}a.value=b;return e.superclass.prototype.updateDisplay.call(this)}});return e}(dat.controllers.NumberController,dat.dom.dom,dat.utils.common); 20 | dat.controllers.NumberControllerSlider=function(f,a,d,e,c){function b(a,b,c,e,d){return e+(a-b)/(c-b)*(d-e)}var q=function(c,e,d,f,p){function z(c){c.preventDefault();var e=a.getOffset(k.__background),d=a.getWidth(k.__background);k.setValue(b(c.clientX,e.left,e.left+d,k.__min,k.__max));return!1}function g(){a.unbind(window,"mousemove",z);a.unbind(window,"mouseup",g);k.__onFinishChange&&k.__onFinishChange.call(k,k.getValue())}q.superclass.call(this,c,e,{min:d,max:f,step:p});var k=this;this.__background= 21 | document.createElement("div");this.__foreground=document.createElement("div");a.bind(this.__background,"mousedown",function(b){a.bind(window,"mousemove",z);a.bind(window,"mouseup",g);z(b)});a.addClass(this.__background,"slider");a.addClass(this.__foreground,"slider-fg");this.updateDisplay();this.__background.appendChild(this.__foreground);this.domElement.appendChild(this.__background)};q.superclass=f;q.useDefaultStyles=function(){d.inject(c)};e.extend(q.prototype,f.prototype,{updateDisplay:function(){var a= 22 | (this.getValue()-this.__min)/(this.__max-this.__min);this.__foreground.style.width=100*a+"%";return q.superclass.prototype.updateDisplay.call(this)}});return q}(dat.controllers.NumberController,dat.dom.dom,dat.utils.css,dat.utils.common,"/**\r\n * dat-gui JavaScript Controller Library\r\n * http://code.google.com/p/dat-gui\r\n *\r\n * Copyright 2011 Data Arts Team, Google Creative Lab\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n */\r\n\r\n.slider {\r\n box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);\r\n height: 1em;\r\n border-radius: 1em;\r\n background-color: #eee;\r\n padding: 0 0.5em;\r\n overflow: hidden;\r\n}\r\n\r\n.slider-fg {\r\n padding: 1px 0 2px 0;\r\n background-color: #aaa;\r\n height: 1em;\r\n margin-left: -0.5em;\r\n padding-right: 0.5em;\r\n border-radius: 1em 0 0 1em;\r\n}\r\n\r\n.slider-fg:after {\r\n display: inline-block;\r\n border-radius: 1em;\r\n background-color: #fff;\r\n border: 1px solid #aaa;\r\n content: '';\r\n float: right;\r\n margin-right: -1em;\r\n margin-top: -1px;\r\n height: 0.9em;\r\n width: 0.9em;\r\n}"); 23 | dat.controllers.FunctionController=function(f,a,d){var e=function(c,b,d){e.superclass.call(this,c,b);var f=this;this.__button=document.createElement("div");this.__button.innerHTML=void 0===d?"Fire":d;a.bind(this.__button,"click",function(a){a.preventDefault();f.fire();return!1});a.addClass(this.__button,"button");this.domElement.appendChild(this.__button)};e.superclass=f;d.extend(e.prototype,f.prototype,{fire:function(){this.__onChange&&this.__onChange.call(this);this.__onFinishChange&&this.__onFinishChange.call(this, 24 | this.getValue());this.getValue().call(this.object)}});return e}(dat.controllers.Controller,dat.dom.dom,dat.utils.common); 25 | dat.controllers.BooleanController=function(f,a,d){var e=function(c,b){e.superclass.call(this,c,b);var d=this;this.__prev=this.getValue();this.__checkbox=document.createElement("input");this.__checkbox.setAttribute("type","checkbox");a.bind(this.__checkbox,"change",function(){d.setValue(!d.__prev)},!1);this.domElement.appendChild(this.__checkbox);this.updateDisplay()};e.superclass=f;d.extend(e.prototype,f.prototype,{setValue:function(a){a=e.superclass.prototype.setValue.call(this,a);this.__onFinishChange&& 26 | this.__onFinishChange.call(this,this.getValue());this.__prev=this.getValue();return a},updateDisplay:function(){!0===this.getValue()?(this.__checkbox.setAttribute("checked","checked"),this.__checkbox.checked=!0):this.__checkbox.checked=!1;return e.superclass.prototype.updateDisplay.call(this)}});return e}(dat.controllers.Controller,dat.dom.dom,dat.utils.common); 27 | dat.color.toString=function(f){return function(a){if(1==a.a||f.isUndefined(a.a)){for(a=a.hex.toString(16);6>a.length;)a="0"+a;return"#"+a}return"rgba("+Math.round(a.r)+","+Math.round(a.g)+","+Math.round(a.b)+","+a.a+")"}}(dat.utils.common); 28 | dat.color.interpret=function(f,a){var d,e,c=[{litmus:a.isString,conversions:{THREE_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);return null===a?!1:{space:"HEX",hex:parseInt("0x"+a[1].toString()+a[1].toString()+a[2].toString()+a[2].toString()+a[3].toString()+a[3].toString())}},write:f},SIX_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9]{6})$/i);return null===a?!1:{space:"HEX",hex:parseInt("0x"+a[1].toString())}},write:f},CSS_RGB:{read:function(a){a=a.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); 29 | return null===a?!1:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3])}},write:f},CSS_RGBA:{read:function(a){a=a.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);return null===a?!1:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3]),a:parseFloat(a[4])}},write:f}}},{litmus:a.isNumber,conversions:{HEX:{read:function(a){return{space:"HEX",hex:a,conversionName:"HEX"}},write:function(a){return a.hex}}}},{litmus:a.isArray,conversions:{RGB_ARRAY:{read:function(a){return 3!= 30 | a.length?!1:{space:"RGB",r:a[0],g:a[1],b:a[2]}},write:function(a){return[a.r,a.g,a.b]}},RGBA_ARRAY:{read:function(a){return 4!=a.length?!1:{space:"RGB",r:a[0],g:a[1],b:a[2],a:a[3]}},write:function(a){return[a.r,a.g,a.b,a.a]}}}},{litmus:a.isObject,conversions:{RGBA_OBJ:{read:function(b){return a.isNumber(b.r)&&a.isNumber(b.g)&&a.isNumber(b.b)&&a.isNumber(b.a)?{space:"RGB",r:b.r,g:b.g,b:b.b,a:b.a}:!1},write:function(a){return{r:a.r,g:a.g,b:a.b,a:a.a}}},RGB_OBJ:{read:function(b){return a.isNumber(b.r)&& 31 | a.isNumber(b.g)&&a.isNumber(b.b)?{space:"RGB",r:b.r,g:b.g,b:b.b}:!1},write:function(a){return{r:a.r,g:a.g,b:a.b}}},HSVA_OBJ:{read:function(b){return a.isNumber(b.h)&&a.isNumber(b.s)&&a.isNumber(b.v)&&a.isNumber(b.a)?{space:"HSV",h:b.h,s:b.s,v:b.v,a:b.a}:!1},write:function(a){return{h:a.h,s:a.s,v:a.v,a:a.a}}},HSV_OBJ:{read:function(b){return a.isNumber(b.h)&&a.isNumber(b.s)&&a.isNumber(b.v)?{space:"HSV",h:b.h,s:b.s,v:b.v}:!1},write:function(a){return{h:a.h,s:a.s,v:a.v}}}}}];return function(){e=!1; 32 | var b=1\r\n\r\n Here\'s the new load parameter for your GUI\'s constructor:\r\n\r\n \r\n\r\n
\r\n\r\n Automatically save\r\n values to localStorage on exit.\r\n\r\n
The values saved to localStorage will\r\n override those passed to dat.GUI\'s constructor. This makes it\r\n easier to work incrementally, but localStorage is fragile,\r\n and your friends may not see the same values you do.\r\n \r\n
\r\n \r\n
\r\n\r\n', 59 | ".dg {\r\n /** Clear list styles */\r\n /* Auto-place container */\r\n /* Auto-placed GUI's */\r\n /* Line items that don't contain folders. */\r\n /** Folder names */\r\n /** Hides closed items */\r\n /** Controller row */\r\n /** Name-half (left) */\r\n /** Controller-half (right) */\r\n /** Controller placement */\r\n /** Shorter number boxes when slider is present. */\r\n /** Ensure the entire boolean and function row shows a hand */ }\r\n .dg ul {\r\n list-style: none;\r\n margin: 0;\r\n padding: 0;\r\n width: 100%;\r\n clear: both; }\r\n .dg.ac {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n right: 0;\r\n height: 0;\r\n z-index: 0; }\r\n .dg:not(.ac) .main {\r\n /** Exclude mains in ac so that we don't hide close button */\r\n overflow: hidden; }\r\n .dg.main {\r\n -webkit-transition: opacity 0.1s linear;\r\n -o-transition: opacity 0.1s linear;\r\n -moz-transition: opacity 0.1s linear;\r\n transition: opacity 0.1s linear; }\r\n .dg.main.taller-than-window {\r\n overflow-y: auto; }\r\n .dg.main.taller-than-window .close-button {\r\n opacity: 1;\r\n /* TODO, these are style notes */\r\n margin-top: -1px;\r\n border-top: 1px solid #2c2c2c; }\r\n .dg.main ul.closed .close-button {\r\n opacity: 1 !important; }\r\n .dg.main:hover .close-button,\r\n .dg.main .close-button.drag {\r\n opacity: 1; }\r\n .dg.main .close-button {\r\n /*opacity: 0;*/\r\n -webkit-transition: opacity 0.1s linear;\r\n -o-transition: opacity 0.1s linear;\r\n -moz-transition: opacity 0.1s linear;\r\n transition: opacity 0.1s linear;\r\n border: 0;\r\n position: absolute;\r\n line-height: 19px;\r\n height: 20px;\r\n /* TODO, these are style notes */\r\n cursor: pointer;\r\n text-align: center;\r\n background-color: #000; }\r\n .dg.main .close-button:hover {\r\n background-color: #111; }\r\n .dg.a {\r\n float: right;\r\n margin-right: 15px;\r\n overflow-x: hidden; }\r\n .dg.a.has-save > ul {\r\n margin-top: 27px; }\r\n .dg.a.has-save > ul.closed {\r\n margin-top: 0; }\r\n .dg.a .save-row {\r\n position: fixed;\r\n top: 0;\r\n z-index: 1002; }\r\n .dg li {\r\n -webkit-transition: height 0.1s ease-out;\r\n -o-transition: height 0.1s ease-out;\r\n -moz-transition: height 0.1s ease-out;\r\n transition: height 0.1s ease-out; }\r\n .dg li:not(.folder) {\r\n cursor: auto;\r\n height: 27px;\r\n line-height: 27px;\r\n overflow: hidden;\r\n padding: 0 4px 0 5px; }\r\n .dg li.folder {\r\n padding: 0;\r\n border-left: 16px solid rgba(0, 0, 0, 0); }\r\n .dg li.title {\r\n cursor: pointer;\r\n margin-left: -4px; }\r\n .dg .closed li:not(.title),\r\n .dg .closed ul li,\r\n .dg .closed ul li > * {\r\n height: 0;\r\n overflow: hidden;\r\n border: 0; }\r\n .dg .cr {\r\n clear: both;\r\n padding-left: 3px;\r\n height: 27px; }\r\n .dg .property-name {\r\n cursor: default;\r\n float: left;\r\n clear: left;\r\n width: 40%;\r\n overflow: hidden;\r\n text-overflow: ellipsis; }\r\n .dg .c {\r\n float: left;\r\n width: 60%; }\r\n .dg .c input[type=text] {\r\n border: 0;\r\n margin-top: 4px;\r\n padding: 3px;\r\n width: 100%;\r\n float: right; }\r\n .dg .has-slider input[type=text] {\r\n width: 30%;\r\n /*display: none;*/\r\n margin-left: 0; }\r\n .dg .slider {\r\n float: left;\r\n width: 66%;\r\n margin-left: -5px;\r\n margin-right: 0;\r\n height: 19px;\r\n margin-top: 4px; }\r\n .dg .slider-fg {\r\n height: 100%; }\r\n .dg .c input[type=checkbox] {\r\n margin-top: 9px; }\r\n .dg .c select {\r\n margin-top: 5px; }\r\n .dg .cr.function,\r\n .dg .cr.function .property-name,\r\n .dg .cr.function *,\r\n .dg .cr.boolean,\r\n .dg .cr.boolean * {\r\n cursor: pointer; }\r\n .dg .selector {\r\n display: none;\r\n position: absolute;\r\n margin-left: -9px;\r\n margin-top: 23px;\r\n z-index: 10; }\r\n .dg .c:hover .selector,\r\n .dg .selector.drag {\r\n display: block; }\r\n .dg li.save-row {\r\n padding: 0; }\r\n .dg li.save-row .button {\r\n display: inline-block;\r\n padding: 0px 6px; }\r\n .dg.dialogue {\r\n background-color: #222;\r\n width: 460px;\r\n padding: 15px;\r\n font-size: 13px;\r\n line-height: 15px; }\r\n\r\n/* TODO Separate style and structure */\r\n#dg-new-constructor {\r\n padding: 10px;\r\n color: #222;\r\n font-family: Monaco, monospace;\r\n font-size: 10px;\r\n border: 0;\r\n resize: none;\r\n box-shadow: inset 1px 1px 1px #888;\r\n word-wrap: break-word;\r\n margin: 12px 0;\r\n display: block;\r\n width: 440px;\r\n overflow-y: scroll;\r\n height: 100px;\r\n position: relative; }\r\n\r\n#dg-local-explain {\r\n display: none;\r\n font-size: 11px;\r\n line-height: 17px;\r\n border-radius: 3px;\r\n background-color: #333;\r\n padding: 8px;\r\n margin-top: 10px; }\r\n #dg-local-explain code {\r\n font-size: 10px; }\r\n\r\n#dat-gui-save-locally {\r\n display: none; }\r\n\r\n/** Main type */\r\n.dg {\r\n color: #eee;\r\n font: 11px 'Lucida Grande', sans-serif;\r\n text-shadow: 0 -1px 0 #111;\r\n /** Auto place */\r\n /* Controller row,
  • */\r\n /** Controllers */ }\r\n .dg.main {\r\n /** Scrollbar */ }\r\n .dg.main::-webkit-scrollbar {\r\n width: 5px;\r\n background: #1a1a1a; }\r\n .dg.main::-webkit-scrollbar-corner {\r\n height: 0;\r\n display: none; }\r\n .dg.main::-webkit-scrollbar-thumb {\r\n border-radius: 5px;\r\n background: #676767; }\r\n .dg li:not(.folder) {\r\n background: #1a1a1a;\r\n border-bottom: 1px solid #2c2c2c; }\r\n .dg li.save-row {\r\n line-height: 25px;\r\n background: #dad5cb;\r\n border: 0; }\r\n .dg li.save-row select {\r\n margin-left: 5px;\r\n width: 108px; }\r\n .dg li.save-row .button {\r\n margin-left: 5px;\r\n margin-top: 1px;\r\n border-radius: 2px;\r\n font-size: 9px;\r\n line-height: 7px;\r\n padding: 4px 4px 5px 4px;\r\n background: #c5bdad;\r\n color: #fff;\r\n text-shadow: 0 1px 0 #b0a58f;\r\n box-shadow: 0 -1px 0 #b0a58f;\r\n cursor: pointer; }\r\n .dg li.save-row .button.gears {\r\n background: #c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;\r\n height: 7px;\r\n width: 8px; }\r\n .dg li.save-row .button:hover {\r\n background-color: #bab19e;\r\n box-shadow: 0 -1px 0 #b0a58f; }\r\n .dg li.folder {\r\n border-bottom: 0; }\r\n .dg li.title {\r\n padding-left: 16px;\r\n background: black url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;\r\n cursor: pointer;\r\n border-bottom: 1px solid rgba(255, 255, 255, 0.2); }\r\n .dg .closed li.title {\r\n background-image: url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==); }\r\n .dg .cr.boolean {\r\n border-left: 3px solid #806787; }\r\n .dg .cr.function {\r\n border-left: 3px solid #e61d5f; }\r\n .dg .cr.number {\r\n border-left: 3px solid #2fa1d6; }\r\n .dg .cr.number input[type=text] {\r\n color: #2fa1d6; }\r\n .dg .cr.string {\r\n border-left: 3px solid #1ed36f; }\r\n .dg .cr.string input[type=text] {\r\n color: #1ed36f; }\r\n .dg .cr.function:hover, .dg .cr.boolean:hover {\r\n background: #111; }\r\n .dg .c input[type=text] {\r\n background: #303030;\r\n outline: none; }\r\n .dg .c input[type=text]:hover {\r\n background: #3c3c3c; }\r\n .dg .c input[type=text]:focus {\r\n background: #494949;\r\n color: #fff; }\r\n .dg .c .slider {\r\n background: #303030;\r\n cursor: ew-resize; }\r\n .dg .c .slider-fg {\r\n background: #2fa1d6; }\r\n .dg .c .slider:hover {\r\n background: #3c3c3c; }\r\n .dg .c .slider:hover .slider-fg {\r\n background: #44abda; }\r\n", 60 | dat.controllers.factory=function(f,a,d,e,c,b,q){return function(r,m,s,n){var p=r[m];if(q.isArray(s)||q.isObject(s))return new f(r,m,s);if(q.isNumber(p))return q.isNumber(s)&&q.isNumber(n)?new d(r,m,s,n):new a(r,m,{min:s,max:n});if(q.isString(p))return new e(r,m);if(q.isFunction(p))return new c(r,m,"");if(q.isBoolean(p))return new b(r,m)}}(dat.controllers.OptionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.StringController=function(f,a,d){var e= 61 | function(c,b){function d(){f.setValue(f.__input.value)}e.superclass.call(this,c,b);var f=this;this.__input=document.createElement("input");this.__input.setAttribute("type","text");a.bind(this.__input,"keyup",d);a.bind(this.__input,"change",d);a.bind(this.__input,"blur",function(){f.__onFinishChange&&f.__onFinishChange.call(f,f.getValue())});a.bind(this.__input,"keydown",function(a){13===a.keyCode&&this.blur()});this.updateDisplay();this.domElement.appendChild(this.__input)};e.superclass=f;d.extend(e.prototype, 62 | f.prototype,{updateDisplay:function(){a.isActive(this.__input)||(this.__input.value=this.getValue());return e.superclass.prototype.updateDisplay.call(this)}});return e}(dat.controllers.Controller,dat.dom.dom,dat.utils.common),dat.controllers.FunctionController,dat.controllers.BooleanController,dat.utils.common),dat.controllers.Controller,dat.controllers.BooleanController,dat.controllers.FunctionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.OptionController, 63 | dat.controllers.ColorController=function(f,a,d,e,c){function b(a,b,d,e){a.style.background="";c.each(m,function(c){a.style.cssText+="background: "+c+"linear-gradient("+b+", "+d+" 0%, "+e+" 100%); "})}function q(a){a.style.background="";a.style.cssText+="background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);";a.style.cssText+="background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);"; 64 | a.style.cssText+="background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);"}var r=function(f,n){function p(b){u(b);a.bind(window,"mousemove",u);a.bind(window, 65 | "mouseup",m)}function m(){a.unbind(window,"mousemove",u);a.unbind(window,"mouseup",m)}function g(){var a=e(this.value);!1!==a?(t.__color.__state=a,t.setValue(t.__color.toOriginal())):this.value=t.__color.toString()}function k(){a.unbind(window,"mousemove",v);a.unbind(window,"mouseup",k)}function u(b){b.preventDefault();var c=a.getWidth(t.__saturation_field),d=a.getOffset(t.__saturation_field),e=(b.clientX-d.left+document.body.scrollLeft)/c;b=1-(b.clientY-d.top+document.body.scrollTop)/c;1 66 | b&&(b=0);1e&&(e=0);t.__color.v=b;t.__color.s=e;t.setValue(t.__color.toOriginal());return!1}function v(b){b.preventDefault();var c=a.getHeight(t.__hue_field),d=a.getOffset(t.__hue_field);b=1-(b.clientY-d.top+document.body.scrollTop)/c;1b&&(b=0);t.__color.h=360*b;t.setValue(t.__color.toOriginal());return!1}r.superclass.call(this,f,n);this.__color=new d(this.getValue());this.__temp=new d(0);var t=this;this.domElement=document.createElement("div");a.makeSelectable(this.domElement,!1); 67 | this.__selector=document.createElement("div");this.__selector.className="selector";this.__saturation_field=document.createElement("div");this.__saturation_field.className="saturation-field";this.__field_knob=document.createElement("div");this.__field_knob.className="field-knob";this.__field_knob_border="2px solid ";this.__hue_knob=document.createElement("div");this.__hue_knob.className="hue-knob";this.__hue_field=document.createElement("div");this.__hue_field.className="hue-field";this.__input=document.createElement("input"); 68 | this.__input.type="text";this.__input_textShadow="0 1px 1px ";a.bind(this.__input,"keydown",function(a){13===a.keyCode&&g.call(this)});a.bind(this.__input,"blur",g);a.bind(this.__selector,"mousedown",function(b){a.addClass(this,"drag").bind(window,"mouseup",function(b){a.removeClass(t.__selector,"drag")})});var x=document.createElement("div");c.extend(this.__selector.style,{width:"122px",height:"102px",padding:"3px",backgroundColor:"#222",boxShadow:"0px 1px 3px rgba(0,0,0,0.3)"});c.extend(this.__field_knob.style, 69 | {position:"absolute",width:"12px",height:"12px",border:this.__field_knob_border+(0.5>this.__color.v?"#fff":"#000"),boxShadow:"0px 1px 3px rgba(0,0,0,0.5)",borderRadius:"12px",zIndex:1});c.extend(this.__hue_knob.style,{position:"absolute",width:"15px",height:"2px",borderRight:"4px solid #fff",zIndex:1});c.extend(this.__saturation_field.style,{width:"100px",height:"100px",border:"1px solid #555",marginRight:"3px",display:"inline-block",cursor:"pointer"});c.extend(x.style,{width:"100%",height:"100%", 70 | background:"none"});b(x,"top","rgba(0,0,0,0)","#000");c.extend(this.__hue_field.style,{width:"15px",height:"100px",display:"inline-block",border:"1px solid #555",cursor:"ns-resize"});q(this.__hue_field);c.extend(this.__input.style,{outline:"none",textAlign:"center",color:"#fff",border:0,fontWeight:"bold",textShadow:this.__input_textShadow+"rgba(0,0,0,0.7)"});a.bind(this.__saturation_field,"mousedown",p);a.bind(this.__field_knob,"mousedown",p);a.bind(this.__hue_field,"mousedown",function(b){v(b);a.bind(window, 71 | "mousemove",v);a.bind(window,"mouseup",k)});this.__saturation_field.appendChild(x);this.__selector.appendChild(this.__field_knob);this.__selector.appendChild(this.__saturation_field);this.__selector.appendChild(this.__hue_field);this.__hue_field.appendChild(this.__hue_knob);this.domElement.appendChild(this.__input);this.domElement.appendChild(this.__selector);this.updateDisplay()};r.superclass=f;c.extend(r.prototype,f.prototype,{updateDisplay:function(){var a=e(this.getValue());if(!1!==a){var f=!1; 72 | c.each(d.COMPONENTS,function(b){if(!c.isUndefined(a[b])&&!c.isUndefined(this.__color.__state[b])&&a[b]!==this.__color.__state[b])return f=!0,{}},this);f&&c.extend(this.__color.__state,a)}c.extend(this.__temp.__state,this.__color.__state);this.__temp.a=1;var p=0.5>this.__color.v||0.5a&&(a+=1);return{h:360*a,s:c/b,v:b/255}},rgb_to_hex:function(a,d,e){a=this.hex_with_component(0,2,a);a=this.hex_with_component(a,1,d);return a=this.hex_with_component(a,0,e)},component_from_hex:function(a,d){return a>>8*d&255},hex_with_component:function(a,d,e){return e<<(f=8*d)|a&~(255<c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div"); 4 | k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display= 5 | "block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height= 6 | a+"px",m=b,r=0);return b},update:function(){l=this.end()}}}; -------------------------------------------------------------------------------- /WebGL-Automata/lib/igloo-0.1.0.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @version 0.1.2 3 | */ 4 | /** 5 | * Wrap WebGLRenderingContext objects with useful behavior. 6 | * @param {WebGLRenderingContext|HTMLCanvasElement} gl 7 | * @param {Object} [options] to pass to getContext() 8 | * @returns {Igloo} 9 | * @namespace 10 | */ 11 | function Igloo(gl, options) { 12 | var canvas; 13 | if (gl instanceof HTMLCanvasElement) { 14 | canvas = gl; 15 | gl = Igloo.getContext(gl, options); 16 | } else { 17 | canvas = gl.canvas; 18 | } 19 | this.gl = gl; 20 | this.canvas = canvas; 21 | this.defaultFramebuffer = new Igloo.Framebuffer(gl, null); 22 | } 23 | /** 24 | * To be used in a vec2 GL_TRIANGLE_STRIP draw. 25 | * @type {Float32Array} 26 | * @constant 27 | */ 28 | Igloo.QUAD2 = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]); 29 | /** 30 | * Asynchronously or synchronously fetch data from the server. 31 | * @param {string} url 32 | * @param {Function} [callback] if provided, call is asynchronous 33 | * @returns {string} 34 | */ 35 | Igloo.fetch = function(url, callback) { 36 | var xhr = new XMLHttpRequest(); 37 | xhr.open('GET', url, Boolean(callback)); 38 | if (callback != null) { 39 | xhr.onload = function() { 40 | callback(xhr.responseText); 41 | }; 42 | } 43 | xhr.send(); 44 | return xhr.responseText; 45 | }; 46 | /** 47 | * @param {HTMLCanvasElement} canvas 48 | * @param {Object} [options] to pass to getContext() 49 | * @param {boolean} [noerror] If true, return null instead of throwing 50 | * @returns {?WebGLRenderingContext} a WebGL rendering context. 51 | */ 52 | Igloo.getContext = function(canvas, options, noerror) { 53 | var gl; 54 | try { 55 | gl = canvas.getContext('webgl', options || {}) || 56 | canvas.getContext('experimental-webgl', options || {}); 57 | } catch (e) { 58 | gl = null; 59 | } 60 | if (gl == null && !noerror) { 61 | throw new Error('Could not create WebGL context.'); 62 | } else { 63 | return gl; 64 | } 65 | }; 66 | /** 67 | * @param {string} string 68 | * @returns {boolean} True if the string looks like a URL 69 | */ 70 | Igloo.looksLikeURL = function(string) { 71 | return /^[\w+:\/\/]/.exec(string) != null; 72 | }; 73 | /** 74 | * @param {*} object 75 | * @returns {boolean} true if object is an array or typed array 76 | */ 77 | Igloo.isArray = function(object) { 78 | var name = Object.prototype.toString.apply(object, []), 79 | re = / (Float(32|64)|Int(16|32|8)|Uint(16|32|8(Clamped)?))?Array]$/; 80 | return re.exec(name) != null; 81 | }; 82 | /** 83 | * Creates a program from a program configuration. 84 | * 85 | * @param {string} vertex URL or source of the vertex shader 86 | * @param {string} fragment URL or source of the fragment shader 87 | * @param {Function} [transform] Transforms the shaders before compilation 88 | * @returns {Igloo.Program} 89 | */ 90 | Igloo.prototype.program = function(vertex, fragment, transform) { 91 | if (Igloo.looksLikeURL(vertex)) vertex = Igloo.fetch(vertex); 92 | if (Igloo.looksLikeURL(fragment)) fragment = Igloo.fetch(fragment); 93 | if (transform != null) { 94 | vertex = transform(vertex); 95 | fragment = transform(fragment); 96 | } 97 | return new Igloo.Program(this.gl, vertex, fragment); 98 | }; 99 | /** 100 | * Create a new GL_ARRAY_BUFFER with optional data. 101 | * @param {ArrayBuffer|ArrayBufferView} [data] 102 | * @param {GLenum} [usage] 103 | * @returns {Igloo.Buffer} 104 | */ 105 | Igloo.prototype.array = function(data, usage) { 106 | var gl = this.gl, 107 | buffer = new Igloo.Buffer(gl, gl.ARRAY_BUFFER); 108 | if (data != null) { 109 | buffer.update(data, usage == null ? gl.STATIC_DRAW : usage); 110 | } 111 | return buffer; 112 | }; 113 | /** 114 | * Create a new GL_ELEMENT_ARRAY_BUFFER with optional data. 115 | * @param {ArrayBuffer|ArrayBufferView} [data] 116 | * @param {GLenum} [usage] 117 | * @returns {Igloo.Buffer} 118 | */ 119 | Igloo.prototype.elements = function(data, usage) { 120 | var gl = this.gl, 121 | buffer = new Igloo.Buffer(gl, gl.ELEMENT_ARRAY_BUFFER); 122 | if (data != null) { 123 | buffer.update(data, usage == null ? gl.STATIC_DRAW : usage); 124 | } 125 | return buffer; 126 | }; 127 | /** 128 | * @param {TexImageSource} [source] 129 | * @param {GLenum} [format=GL_RGBA] 130 | * @param {GLenum} [wrap=GL_CLAMP_TO_EDGE] 131 | * @param {GLenum} [filter=GL_LINEAR] 132 | * @returns {Igloo.Texture} 133 | */ 134 | Igloo.prototype.texture = function(source, format, wrap, filter) { 135 | var texture = new Igloo.Texture(this.gl, format, wrap, filter); 136 | if (source != null) { 137 | texture.set(source); 138 | } 139 | return texture; 140 | }; 141 | /** 142 | * @param {Igloo.Texture} [texture] 143 | * @returns {Igloo.Framebuffer} 144 | */ 145 | Igloo.prototype.framebuffer = function(texture) { 146 | var framebuffer = new Igloo.Framebuffer(this.gl); 147 | if (texture != null) framebuffer.attach(texture); 148 | return framebuffer; 149 | }; 150 | /** 151 | * Fluent WebGLProgram wrapper for managing variables and data. The 152 | * constructor compiles and links a program from a pair of shaders. 153 | * Throws an exception if compiling or linking fails. 154 | * @param {WebGLRenderingContext} gl 155 | * @param {string} vertex Shader source 156 | * @param {string} fragment Shader source 157 | * @constructor 158 | */ 159 | Igloo.Program = function(gl, vertex, fragment) { 160 | this.gl = gl; 161 | var p = this.program = gl.createProgram(); 162 | gl.attachShader(p, this.makeShader(gl.VERTEX_SHADER, vertex)); 163 | gl.attachShader(p, this.makeShader(gl.FRAGMENT_SHADER, fragment)); 164 | gl.linkProgram(p); 165 | if (!gl.getProgramParameter(p, gl.LINK_STATUS)) { 166 | throw new Error(gl.getProgramInfoLog(p)); 167 | } 168 | this.vars = {}; 169 | }; 170 | /** 171 | * Compile a shader from source. 172 | * @param {number} type 173 | * @param {string} source 174 | * @returns {WebGLShader} 175 | */ 176 | Igloo.Program.prototype.makeShader = function(type, source) { 177 | var gl = this.gl; 178 | var shader = gl.createShader(type); 179 | gl.shaderSource(shader, source); 180 | gl.compileShader(shader); 181 | if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { 182 | return shader; 183 | } else { 184 | //console.log(shader); 185 | throw new Error(gl.getShaderInfoLog(shader)); 186 | } 187 | }; 188 | /** 189 | * Tell WebGL to use this program right now. 190 | * @returns {Igloo.Program} this 191 | */ 192 | Igloo.Program.prototype.use = function() { 193 | this.gl.useProgram(this.program); 194 | return this; 195 | }; 196 | /** 197 | * Declare/set a uniform or set a uniform's data. 198 | * @param {string} name uniform variable name 199 | * @param {number|Array|ArrayBufferView} [value] 200 | * @param {boolean} [i] if true use the integer version 201 | * @returns {Igloo.Program} this 202 | */ 203 | Igloo.Program.prototype.uniform = function(name, value, i) { 204 | if (value == null) { 205 | this.vars[name] = this.gl.getUniformLocation(this.program, name); 206 | } else { 207 | if (this.vars[name] == null) this.uniform(name); 208 | var v = this.vars[name]; 209 | if (Igloo.isArray(value)) { 210 | var method = 'uniform' + value.length + (i ? 'i' : 'f') + 'v'; 211 | this.gl[method](v, value); 212 | } else if (typeof value === 'number' || typeof value === 'boolean') { 213 | if (i) { 214 | this.gl.uniform1i(v, value); 215 | } else { 216 | this.gl.uniform1f(v, value); 217 | } 218 | } else { 219 | throw new Error('Invalid uniform value: ' + value); 220 | } 221 | } 222 | return this; 223 | }; 224 | /** 225 | * Set a uniform's data to a specific matrix. 226 | * @param {string} name uniform variable name 227 | * @param {Array|ArrayBufferView} matrix 228 | * @param {boolean} [transpose=false] 229 | * @returns {Igloo.Program} this 230 | */ 231 | Igloo.Program.prototype.matrix = function(name, matrix, transpose) { 232 | if (this.vars[name] == null) this.uniform(name); 233 | var method = 'uniformMatrix' + Math.sqrt(matrix.length) + 'fv'; 234 | this.gl[method](this.vars[name], Boolean(transpose), matrix); 235 | return this; 236 | }; 237 | /** 238 | * Like the uniform() method, but using integers. 239 | * @returns {Igloo.Program} this 240 | */ 241 | Igloo.Program.prototype.uniformi = function(name, value) { 242 | return this.uniform(name, value, true); 243 | }; 244 | /** 245 | * Declare an attrib or set an attrib's buffer. 246 | * @param {string} name attrib variable name 247 | * @param {WebGLBuffer} [value] 248 | * @param {number} [size] element size (required if value is provided) 249 | * @param {number} [stride=0] 250 | * @returns {Igloo.Program} this 251 | */ 252 | Igloo.Program.prototype.attrib = function(name, value, size, stride) { 253 | var gl = this.gl; 254 | if (value == null) { 255 | this.vars[name] = gl.getAttribLocation(this.program, name); 256 | } else { 257 | if (this.vars[name] == null) this.attrib(name); // get location 258 | value.bind(); 259 | gl.enableVertexAttribArray(this.vars[name]); 260 | gl.vertexAttribPointer(this.vars[name], size, gl.FLOAT, 261 | false, stride == null ? 0 : stride, 0); 262 | } 263 | return this; 264 | }; 265 | /** 266 | * Call glDrawArrays or glDrawElements with this program. 267 | * @param {number} mode 268 | * @param {number} count the number of vertex attribs to render 269 | * @param {GLenum} [type] use glDrawElements of this type 270 | * @returns {Igloo.Program} this 271 | */ 272 | Igloo.Program.prototype.draw = function(mode, count, type) { 273 | var gl = this.gl; 274 | if (type == null) { 275 | gl.drawArrays(mode, 0, count); 276 | } else { 277 | gl.drawElements(mode, count, type, 0); 278 | } 279 | if (gl.getError() !== gl.NO_ERROR) { 280 | throw new Error('WebGL rendering error'); 281 | } 282 | return this; 283 | }; 284 | /** 285 | * Disables all attribs from this program. 286 | * @returns {Igloo.Program} this 287 | */ 288 | Igloo.Program.prototype.disable = function() { 289 | for (var attrib in this.vars) { 290 | var location = this.vars[attrib]; 291 | if (this.vars.hasOwnProperty(attrib)) { 292 | if (typeof location === 'number') { 293 | this.gl.disableVertexAttribArray(location); 294 | } 295 | } 296 | } 297 | return this; 298 | }; 299 | /** 300 | * Fluent WebGLBuffer wrapper. 301 | * @param {WebGLRenderingContext} gl 302 | * @param {GLenum} [target] either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER 303 | * @returns {WebGLProgram} 304 | * @constructor 305 | */ 306 | Igloo.Buffer = function(gl, target) { 307 | this.gl = gl; 308 | this.buffer = gl.createBuffer(); 309 | this.target = (target == null ? gl.ARRAY_BUFFER : target); 310 | this.size = -1; 311 | }; 312 | /** 313 | * Binds this buffer to ARRAY_BUFFER. 314 | * @returns {Igloo.Buffer} this 315 | */ 316 | Igloo.Buffer.prototype.bind = function() { 317 | this.gl.bindBuffer(this.target, this.buffer); 318 | return this; 319 | }; 320 | /** 321 | * @param 322 | * @param {ArrayBuffer|ArrayBufferView} data 323 | * @param {GLenum} [usage] 324 | * @returns {Igloo.Buffer} this 325 | */ 326 | Igloo.Buffer.prototype.update = function(data, usage) { 327 | var gl = this.gl; 328 | if (data instanceof Array) { 329 | data = new Float32Array(data); 330 | } 331 | usage = usage == null ? gl.DYNAMIC_DRAW : usage; 332 | this.bind(); 333 | if (this.size !== data.byteLength) { 334 | gl.bufferData(this.target, data, usage); 335 | this.size = data.byteLength; 336 | } else { 337 | gl.bufferSubData(this.target, 0, data); 338 | } 339 | return this; 340 | }; 341 | /** 342 | * Create a new texture, optionally filled blank. 343 | * @param {WebGLRenderingContext} gl 344 | * @param {GLenum} [format=GL_RGBA] 345 | * @param {GLenum} [wrap=GL_CLAMP_TO_EDGE] 346 | * @param {GLenum} [filter=GL_LINEAR] 347 | * @returns {Igloo.Texture} 348 | */ 349 | Igloo.Texture = function(gl, format, wrap, filter) { 350 | this.gl = gl; 351 | var texture = this.texture = gl.createTexture(); 352 | gl.bindTexture(gl.TEXTURE_2D, texture); 353 | wrap = wrap == null ? gl.CLAMP_TO_EDGE : wrap; 354 | filter = filter == null ? gl.LINEAR : filter; 355 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap); 356 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap); 357 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter); 358 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter); 359 | this.format = format = format == null ? gl.RGBA : format; 360 | }; 361 | /** 362 | * @param {number} [unit] active texture unit to bind 363 | * @returns {Igloo.Texture} 364 | */ 365 | Igloo.Texture.prototype.bind = function(unit) { 366 | var gl = this.gl; 367 | if (unit != null) { 368 | gl.activeTexture(gl.TEXTURE0 + unit); 369 | } 370 | gl.bindTexture(gl.TEXTURE_2D, this.texture); 371 | return this; 372 | }; 373 | /** 374 | * Set texture to particular size, filled with vec4(0, 0, 0, 1). 375 | * @param {number} width 376 | * @param {number} height 377 | * @returns {Igloo.Texture} 378 | */ 379 | Igloo.Texture.prototype.blank = function(width, height) { 380 | var gl = this.gl; 381 | this.bind(); 382 | gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 383 | 0, this.format, gl.UNSIGNED_BYTE, null); 384 | return this; 385 | }; 386 | /** 387 | * Set the texture to a particular image. 388 | * @param {Array|ArrayBufferView|TexImageSource} source 389 | * @param {number} [width] 390 | * @param {number} [height] 391 | * @returns {Igloo.Texture} 392 | */ 393 | Igloo.Texture.prototype.set = function(source, width, height) { 394 | var gl = this.gl; 395 | this.bind(); 396 | if (source instanceof Array) source = new Uint8Array(source); 397 | if (width != null || height != null) { 398 | gl.texImage2D(gl.TEXTURE_2D, 0, this.format, 399 | width, height, 0, this.format, 400 | gl.UNSIGNED_BYTE, source); 401 | } else { 402 | gl.texImage2D(gl.TEXTURE_2D, 0, this.format, 403 | this.format, gl.UNSIGNED_BYTE, source); 404 | } 405 | return this; 406 | }; 407 | /** 408 | * Set part of the texture to a particular image. 409 | * @param {Array|ArrayBufferView|TexImageSource} source 410 | * @param {number} xoff 411 | * @param {number} yoff 412 | * @param {number} [width] 413 | * @param {number} [height] 414 | * @returns {Igloo.Texture} 415 | */ 416 | Igloo.Texture.prototype.subset = function(source, xoff, yoff, width, height) { 417 | var gl = this.gl; 418 | this.bind(); 419 | if (source instanceof Array) source = new Uint8Array(source); 420 | if (width != null || height != null) { 421 | gl.texSubImage2D(gl.TEXTURE_2D, 0, xoff, yoff, 422 | width, height, 423 | this.format, gl.UNSIGNED_BYTE, source); 424 | } else { 425 | gl.texSubImage2D(gl.TEXTURE_2D, 0, xoff, yoff, 426 | this.format, gl.UNSIGNED_BYTE, source); 427 | } 428 | return this; 429 | }; 430 | /** 431 | * Copy part/all of the current framebuffer to this image. 432 | * @param {Array|ArrayBufferView|TexImageSource} source 433 | * @param {number} x 434 | * @param {number} y 435 | * @param {number} width 436 | * @param {number} height 437 | * @returns {Igloo.Texture} 438 | */ 439 | Igloo.Texture.prototype.copy = function(x, y, width, height) { 440 | var gl = this.gl; 441 | gl.copyTexImage2D(gl.TEXTURE_2D, 0, this.format, x, y, width, height, 0); 442 | return this; 443 | }; 444 | /** 445 | * @param {WebGLRenderingContext} gl 446 | * @param {WebGLFramebuffer} [framebuffer] to be wrapped (null for default) 447 | * @returns {Igloo.Framebuffer} 448 | */ 449 | Igloo.Framebuffer = function(gl, framebuffer) { 450 | this.gl = gl; 451 | this.framebuffer = 452 | arguments.length == 2 ? framebuffer : gl.createFramebuffer(); 453 | this.renderbuffer = null; 454 | }; 455 | /** 456 | * @returns {Igloo.Framebuffer} 457 | */ 458 | Igloo.Framebuffer.prototype.bind = function() { 459 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer); 460 | return this; 461 | }; 462 | /** 463 | * @returns {Igloo.Framebuffer} 464 | */ 465 | Igloo.Framebuffer.prototype.unbind = function() { 466 | this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null); 467 | return this; 468 | }; 469 | /** 470 | * @param {Igloo.Texture} texture 471 | * @returns {Igloo.Framebuffer} 472 | */ 473 | Igloo.Framebuffer.prototype.attach = function(texture) { 474 | var gl = this.gl; 475 | this.bind(); 476 | gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, 477 | gl.TEXTURE_2D, texture.texture, 0); 478 | return this; 479 | }; 480 | /** 481 | * Attach a renderbuffer as a depth buffer for depth-tested rendering. 482 | * @param {number} width 483 | * @param {number} height 484 | * @returns {Igloo.Framebuffer} 485 | */ 486 | Igloo.Framebuffer.prototype.attachDepth = function(width, height) { 487 | var gl = this.gl; 488 | this.bind(); 489 | if (this.renderbuffer == null) { 490 | this.renderbuffer = gl.createRenderbuffer(); 491 | gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 492 | width, height); 493 | gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, 494 | gl.RENDERBUFFER, this.renderbuffer); 495 | } 496 | return this; 497 | }; -------------------------------------------------------------------------------- /WebGL-Automata/lib/jquery-2.1.1.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ 2 | !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="
    ",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+Math.random()}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b) 3 | },_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
    "],col:[2,"","
    "],tr:[2,"","
    "],td:[3,"","
    "],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("