var x=new Array();
var y=new Array();
var point=new Array();
function sample(){
mode=1;
for(s=1;s<101;s++){
x[s]=50;
y[s]=100;
point[s]=0;
}
var timer;
var delay = 100;
var loop = function () {
for(s=1;s<101;s++){
y[s]=y[s]-1;
}
for(s=1;s<101;s++){
dx=0;
r1=Math.random();
if(r1>0.7)dx=-1;
if(r1<0.3)dx=1;
x[s]=x[s]+dx;
if(x[s]>100)x[s]=100;
if(x[s]<1)x[s]=1;
if(y[s]<0)point[s]=0;;
}
sx=0;
for(s=1;s<101;s++){
if(point[s]<50)sx=s;
}
if(Math.random()>0.9){
point[sx]=100;
x[sx]=50;
y[sx]=100;
}
check();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function check(){
for(s=1;s<101;s++){
h=0;
if(x[s]==50)h=h+1;
if(y[s]==50)h=h+1;
if(point[s]>50)h=h+1;
if(h==3)mode=2;
}
}
function paint(){
var sub=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<101;s++){
if(point[s]>50)str=str+sub.rect(5*x[s],500-5*y[s],5,5,"blue");
}
if(mode==2)str=str+sub.rect(0,0,500,500,"red");
str=str+"</svg>";
$("#memo").html(str);
mode=1;
}
最終更新:2016年01月03日 17:07