LIFE

ID
Nazov / Name:
Popis / Description:
Dlzka / Length:
Testovane pod / Tested under:

 

148
p148.html / p148.zip
Simulacia hry LIFE
1465b
NN 4.04

UKAZKA / CLICK HERE

Zdrojovy tvar / Source code:

<html> <BODY BGCOLOR="#FFFFFF"> <form> Podla potreby porozsvecujte gulicky a potom stlacte <input type=button value="START" onClick="if (active == 0) nextgen(1)"> </form> <script language=javascript> <!-- var cell = new Array(451); var index; var row; var col; var active = 0; function toggle(r, c) { index = 24 * ((r / 25) - 1) + (c - 1); if (cell[r+c] == 0) { cell[r+c] = 1; window.document.images[index].src = "images/reddot.gif"; } else { cell[r+c] = 0; window.document.images[index].src = "images/nodot.gif"; } } function redisplay() { var lifeVal; index = 0; for (row = 25; row < 425; row += 25) for (col = 1; col <= 24; col++) { lifeVal = cell[row+col]; if (lifeVal == 0) window.document.images[index].src = "images/nodot.gif"; else if (lifeVal == 1) { window.document.images[index].src = "images/reddot.gif"; cell[row+col] = 2; } else if (lifeVal < 30000) window.document.images[index].src = "images/bluedot.gif"; else { window.document.images[index].src = "images/nodot.gif"; cell[row+col] = 0; } index++; } } function nextgen(change) { var neighbors; active = 1; for (row = 25; row < 425; row += 25) for (col = 1; col <= 24; col++) { index = row + col; neighbors = 0; if (cell[index-26] >= 2) neighbors++; if (cell[index-25] >= 2) neighbors++; if (cell[index-24] >= 2) neighbors++; if (cell[index-1] >= 2) neighbors++; if (cell[index+1] >= 2) neighbors++; if (cell[index+24] >= 2) neighbors++; if (cell[index+25] >= 2) neighbors++; if (cell[index+26] >= 2) neighbors++; if (neighbors == 3) { if (cell[index] == 0) change = 1; cell[index]++; } else if (neighbors == 2) { if (cell[index] > 1) cell[index]++; } else if (cell[index] > 1) { change = 1; cell[index] = 30000; } } redisplay(); if (change == 1) setTimeout("nextgen(0)", 500); else { alert("Pattern is stable"); active = 0; } } for (index = 0; index < 451; index++) cell[index] = 0; cell[212] = 1; cell[213] = 1; cell[236] = 1; cell[237] = 1; cell[262] = 1; if (top.frames.length > 1) { window.document.fgColor=top.frames[1].document.fgColor; window.document.linkColor=top.frames[1].document.linkColor; window.document.vlinkColor=top.frames[1].document.vlinkColor; window.document.bgColor=top.frames[1].document.bgColor; } for (row = 25; row < 425; row += 25) { for (col = 1; col <= 24; col++) { window.document.write("<a href=javascript:toggle("+row+","+col+")>"); if (cell[row+col] == 1) window.document.write("<img src=images/reddot.gif border=0></a>"); else window.document.write("<img src=images/nodot.gif border=0></a>"); } window.document.writeln("<br>"); } // --> </script> </body> </HTML>
[ Navrat / BACK ]