開始を押すとランダムな開始位置よりアミダを辿って下の番号に到達します。ソースは相当汚いですが、動けばいいや的なノリで組みました...、ご助言頂ければありがたいです。
function makeAmida(num, len){
if(num > 20) alert("20人以下でお願いします。")
var a = new Array(len);
for(i=0; i<len; i++) { // 縦
a[i] = new Array(num);
for(j=0; j<2*num-1; j++) { // 横
if (j%2) { // 偶数番目は2通り
if(a[i][j-1] == "┣") a[i][j] = "━";
else a[i][j] = " ";
} else { // 奇数番目は最初、最後を場合分け
if(a[i][j-1] == "━") a[i][j] = "┫";
else {
if(j==2*(num-1)) a[i][j] = "┃";
else a[i][j] = (Math.floor(Math.random()*2))? "┃" : "┣";
}
}
}
}
return a;
}function writeAmida(matrix) {
var nums = new Array("①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩","⑪","⑫","⑬","⑭","⑮","⑯","⑰","⑱","⑲","⑳");
document.write("<br />");
for(i=0; i<matrix.length; i++) {
for(j=0; j<matrix[0].length; j++) {
document.write('<span class="amida" id="amida' + i + "l" + j + '">');
document.write(matrix[i][j]);
document.write('</span>');
}
document.write("<br />");
}
for(i=0; i<(matrix[0].length+1)/2; i++) {
document.write('<span class="amida" id="num' + i + '">');
document.write(nums[i]);
document.write(' </span>');
}
}function traceAmida(matrix,i,i2,j,j2,step) {
// numに人数、lenに縦の長さ。これを実行すればOK。
pre_i = i; pre_j = j;
// n:人数 matrix[0].length: 2n-1 行列から人数を逆算⇒あみだの開始位置は偶数番目
if(i==0 && j==0 && step==0) {
pre_i = -1;
j = 2*Math.floor(Math.random()*(matrix[0].length+1)/2); // 最初は開始位置ランダム
}
else {
if(matrix[i][j] == "━") j += (j - j2);
else if(matrix[i][j] == "┫") {
if(i-i2) j--; // 下向きに速度を持っていたら左
else i++; // 横向きだったら下へ
}
else if(matrix[i][j] == "┣") {
if(i-i2) j++; // 下向きに速度を持っていたら右
else i++; // 横向きだったら下へ
}
else i++; // ┃
}
if(!(i==matrix.length)) {
document.getElementById("amida" + i + "l" + j).style.color = (step)? "f00" : "ff0";
step++;
setTimeout(function(){ traceAmida(matrix, i, pre_i, j, pre_j, step) }, 50);
} else {
document.getElementById("num" + (j/2)).style.color = "#00f";
}
}
function amida(num, len){
var a = makeAmida(num, len);
writeAmida(a);
traceAmida(a,0,0,0,0,0);
}
このブログ記事を参照しているブログ一覧: JavaScriptによるあみだくじ
このブログ記事に対するトラックバックURL: http://www.hecomi.com/mt/mt-tb.cgi/68
Introduction
凹みTipsはHTML、CSS、PHP、ActionScript3.0、JavaScriptからAjaxまで初心者の凹が試行錯誤繰り返しながら勉強していくサイトです。一緒に勉強していきましょう!
Categories
Recent Entries
Monthly Archives
コメント
mother son oral porn
indian and sex
casino casinos download
ass beautiful porn