| 353 | } |
| 354 | } |
| 355 | fx6() { |
| 356 | // max iterations for each cell to change the current value |
| 357 | const MAX_CELL_ITERATIONS = 15; |
| 358 | let finished = 0; |
| 359 | const loop = (line, cell, iteration = 0) => { |
| 360 | cell.cache = {'state': cell.state, 'color': cell.color}; |
| 361 | |
| 362 | if ( iteration === MAX_CELL_ITERATIONS-1 ) { |
| 363 | cell.set(cell.original); |
| 364 | |
| 365 | cell.color = cell.originalColor; |
| 366 | cell.DOM.el.style.color = cell.color; |
| 367 | |
| 368 | ++finished; |
| 369 | if ( finished === this.totalChars ) { |
| 370 | this.isAnimating = false; |
| 371 | } |
| 372 | } |
| 373 | else { |
| 374 | cell.set(this.getRandomChar()); |
| 375 | |
| 376 | cell.color = ['#2b4539', '#61dca3', '#61b3dc'][Math.floor(Math.random() * 3)] |
| 377 | cell.DOM.el.style.color = cell.color |
| 378 | } |
| 379 | |
| 380 | ++iteration; |
| 381 | if ( iteration < MAX_CELL_ITERATIONS ) { |
| 382 | setTimeout(() => loop(line, cell, iteration), randomNumber(30,110)); |
| 383 | } |
| 384 | }; |
| 385 | |
| 386 | for (const line of this.lines) { |
| 387 | for (const cell of line.cells) { |
| 388 | setTimeout(() => loop(line, cell), (line.position+1)*80); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | /** |
| 393 | * call the right effect method (defined in this.effects) |
| 394 | * @param {string} effect - effect type |