var ball=new Array();
var bx=new Array();
var by=new Array();
var dx=new Array();
var dy=new Array();
function sample(){
mode=0;
for(s=1;s<101;s++){
ball[s] = 0;
dx[s] = 0;
dy[s] = 0;
bx[s] = 0;
by[s] = 0;
}
var timer;
var delay = 100;
var loop = function () {
if(Math.random()>0.7)strike();
move();
delta();
turn();
wall();
death();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function paint(){
var sub3=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
if(mode>50)str=str+sub3.rect(0,0,500,500,"red");
for(s=1;s<101;s++){
if(ball[s]>50)str=str+sub3.rect(5*bx[s],500-5*by[s],5,5,"black");
}
str=str+"</svg>";
$("#memo").html(str);
}
function turn(){
for(s=1;s<101;s++){
if(Math.random()>0.8)dx[s]=-1*dx[s];
}
}
function strike(){
var s,sx;
sx=0;
for(s=1;s<101;s++){
if(ball[s]<50)sx=s;
}
if(sx>0){
ball[sx]=100;
bx[sx]=50;
by[sx]=100;
dx[sx]=1;
dy[sx]=-1;
}
}
function delta(){
for(s=1;s<101;s++){
h=0;
if(bx[s]==50)h=h+1;
if(by[s]==50)h=h+1;
if(ball[s]>50)h=h+1;
if(h==3)mode=100;
}
if(Math.random()>0.9)mode=0;
}
function move(){
for(s=1;s<101;s++){
bx[s]=bx[s]+dx[s];
by[s]=by[s]+dy[s];
}
}
function wall(){
for(s=1;s<101;s++){
h=0
if(bx[s]>100)h=h+1;
if(dx[s]>0)h=h+1;
if(h==2)dx[s]=-1*dx[s];
}
for(s=1;s<101;s++){
h=0
if(bx[s]<0)h=h+1;
if(dx[s]<0)h=h+1;
if(h==2)dx[s]=-1*dx[s];
}
}
function death(){
for(s=1;s<101;s++){
if(by[s]<0)ball[s]=0;
}
}
最終更新:2015年10月21日 15:19