var x = new Array();
var y = new Array()
var dir = new Array();
var number_dir = new Array();
var ball;
function sample(){
faststep();
ball = 5;
var timer;
var delay = 1000;
var loop = function () {
move();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function move(){
n1 = number_dir[ball]*Math.random();
n2 = Math.floor(n1)+1;
ball = dir[ball][n2];
}
function faststep(){
tx=0;
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
for(t=1;t<26;t++){
dir[t] = new Array();
}
for(t=1;t<26;t++){
tx = 0;
for(s1=-1;s1<2;s1++){
for(s2=-1;s2<2;s2++){
x1 = x[t] + s1;
y1 = y[t] + s2;
sx = search(x1, y1);
if(sx==t)sx=0;
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[t][tx] = sx;
}}
number_dir[t] = tx;
}
}
function search(x1,y1){
var s,sx,h;
sx=0;
for (s = 1; s < 26; s++) {
h = 0;
if (x[s] == x1) h = h + 1;
if (y[s] == y1) h = h + 1;
if (h == 2) sx = s;
}
return sx;
}
function paint(){
var sub=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<26;s++){
str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"red");
}
str=str+sub.rect(100*x[ball]-100,100*y[ball]-100,100,100,"blue");
str=str+"</svg>";
$("#memo").html(str);
}
最終更新:2015年06月15日 09:37