[過去ログ] 【初心者】課題をクリアしていくスレ【講習会】 (787レス)
前次1-
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
リロード規制です。10分ほどで解除するので、他のブラウザへ避難してください。
377: 名前は開発中のものです。 [sage] 04/07/20 17:58 ID:5+HMeKnI(1/2) AAS
課題11 ライフゲーム

<html><head><style type="text/css"><!--
.cell{border:1px solid Black;font-size:10px;color:Red;padding:0px;width:10px;height:10px;}
--></style></head><body onload="resize()">
<input type=button onclick="doing = !doing;this.value=doing?'停止':'開始';go()" value="開始">
<input type=button value="ランダム" onclick="setField(1)"><input type=button value="クリア" onclick="setField(0)"><br>
横<input id=horz type=text value="20"><br>縦<input id=vert type=text value="20"><input type=button value="設定" onclick="resize()">
<div id=field></div><script language="Javascript"><!--
var cols, rows, timerID, doing = false, map = new Array(), elms = new Array();
function setField(k){
if (doing) return;
for (i = 0; i < cols * rows; i++){
map[i] = k ? Math.floor(Math.random() * 2) : 0;
elms[i].innerHTML = map[i] == 1 ? '●' : ' ';
}
}
function resize(){
if (doing) return;
cols = document.getElementById('horz').value - 0;
rows = document.getElementById('vert').value - 0;
var str = '<table cellspacing=0 style="cursor:pointer;">';
for (var i = 0; i < rows; i++){
str += '<tr>';
for (var j = 0; j < cols; j++){
num = i * cols + j;
str += '<td id='+num+' class=cell onclick="set(this)"> </td>';
map[num] = 0;
378: 名前は開発中のものです。 [sage] 04/07/20 17:59 ID:5+HMeKnI(2/2) AAS
}
str += '</tr>';
}
document.getElementById('field').innerHTML = str + '</table>';
for (i = 0; i < cols * rows; i++) elms[i] = document.getElementById(i + '');
}
function set(elm){
if (doing) return;
map[elm.id] = 1 - map[elm.id];
elm.innerHTML = map[elm.id] ? '●' : ' ';
}
function get(y, x){
if (x < 0 || y < 0 || x > cols - 1 || y > rows - 1) return 0;
return map[y * cols + x];
}
function go(){
clearTimeout(timerID);
var newMap = new Array();
for (i = 0; i < rows; i++){
for (j = 0; j < cols; j++){
next = get(i-1,j-1) + get(i-1,j) + get(i-1,j+1) + get(i,j-1) + get(i,j+1) + get(i+1,j-1) + get(i+1,j) + get(i+1,j+1);
newMap[i * cols + j] = (next == 2) ? map[i * cols + j] : (next == 3) ? 1 : 0;
}
}
for (i = 0; i < cols * rows; i++){
map[i] = newMap[i];
elms[i].innerHTML = (map[i] == 1) ? '●' : ' ';
}
timerID = doing ? setTimeout(go, 500) : 0;
}
//--></script></body></html>
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.043s