var ax=new Array();
var ay=new Array();
var bx=new Array();
var by=new Array();
var a=new Array();
var b=new Array();
function sample() {
for(s=1;s<11;s++){
a[s]=100;
b[s]=100;
ay[s]=1;
ax[s]=s;
by[s]=10;
bx[s]=s;
}
var timer;
var delay = 1000;
var loop = function () {
move_a();
move_b();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function move_a(){
for(s=1;s<11;s++){
y1=ay[s]+1;
if(y1>10)y1=10;
ch=check_a(ax[s],y1);
if(ch<50)ay[s]=y1;
}
}
function move_b(){
for(s=1;s<11;s++){
y1=by[s]-1;
if(y1<1)y1=1;
ch=check_b(bx[s],y1);
if(ch<50)by[s]=y1;
}
}
function check_a(px,py){
ch=0;
for(sx=1;sx<11;sx++){
h=0;
if(bx[sx]==px)h=h+1;
if(by[sx]==py)h=h+1;
if(h==2)ch=100;
}
return ch;
}
function check_b(px,py){
ch=0;
for(sx=1;sx<11;sx++){
h=0;
if(ax[sx]==px)h=h+1;
if(ay[sx]==py)h=h+1;
if(h==2)ch=100;
}
return ch;
}
function paint(){
var sub3=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<11;s++){
x1=ax[s];
y1=ay[s];
if(a[s]>50)str=str+sub3.rect(50*x1-50,500-50*y1,50,50,"red");
}
for(s=1;s<11;s++){
x1=bx[s];
y1=by[s];
if(b[s]>50)str=str+sub3.rect(50*x1-50,500-50*y1,50,50,"blue");
}
str=str+"</svg>";
$("#memo").html(str);
}
最終更新:2016年11月17日 10:23