アットウィキロゴ

fig

var x = new Array();
var y = new Array()
var dir = new Array();
var number_dir = new Array();
var ball=new Array();
var a=new Array();
var area=new Array();
 
function sample(){
 
faststep();
 
for(s=1;s<11;s++){
ball[s] = 5;
a[s] = 1;
}
 
var timer;
var delay = 1000;
 
var loop = function () {
 
    move();
 
    check();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
 
}
 
function move(){
 
    for (s = 1; s < 11; s++) {
        sx = ball[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        ball[s] = dir[sx][n2];
    }
 
    for (s = 1; s < 11; s++) {
        sx = a[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        a[s] = dir[sx][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();
area[t] = 0;
} 
 
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 check(){
 
 
for(s=1;s<11;s++){
sx=ball[s];
area[sx] = 1;
}
for(s=1;s<11;s++){
sx=a[s];
area[sx] = 2;
}
 
 
}
 
 
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");
if(area[s]==1)str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"blue");
if(area[s]==2)str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"green");
}
 
 
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
最終更新:2015年06月15日 09:48