var delta=new Array();
var a=new Array();
var cx,cy;
function sample(){
k=2;
for(s=1;s<21;s++){
delta[s]=1;
}
for(s=1;s<70;s++){
a[s]=new Array();
}
var timer;
var delay = 100;
var loop = function () {
for(s=1;s<70;s++){
for(sx=1;sx<70;sx++){
a[s][sx]=0;
}}
cx=1;
cy=1;
for(tr=1;tr<21;tr++){
if(delta[tr]==1)fillx();
if(delta[tr]==2)filly();
check();
}
paint();
move();
if(delta[20]==3){
for(s=1;s<21;s++){
delta[s]=1;
}
k=k+1;
if(k>60)k=2;
}
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function move(){
var s;
delta[1]=delta[1]+1;
for(s=1;s<20;s++){
if(delta[s]>2)delta[s+1]=delta[s+1]+1;
if(delta[s]>2)delta[s]=1;
}
}
function paint(){
var sub=new svgpaint();
str="<svg width=\"700\" height=\"700\">";
for(s=1;s<61;s++){
for(sx=1;sx<61;sx++){
if(a[s][sx]>50)str=str+sub.rect(10*sx,10*s,10,10,"blue");
if(a[s][sx]<50)str=str+sub.rect(10*sx,10*s,10,10,"red");
}}
str=str+"</svg>";
$("#memo").html(str);
}
function fillx(){
a[cy][cx]=100;
a[cy][cx+1]=100;
a[cy][cx+2]=100;
a[cy+1][cx]=100;
a[cy+1][cx+1]=100;
a[cy+1][cx+2]=100;
}
function filly(){
a[cy][cx]=100;
a[cy][cx+1]=100;
a[cy+1][cx]=100;
a[cy+1][cx+1]=100;
a[cy+2][cx]=100;
a[cy+2][cx+1]=100;
}
function check(){
var s,sx;
miny=999;
for(s=1;s<61;s++){
for(sx=1;sx<61;sx++){
h=0;
if(a[s][sx]==0)h=h+1;
if(s<miny)h=h+1;
if(sx>k)h=0;
if(h==2)miny=s;
}
}
minx=9999;
for(sx=1;sx<61;sx++){
h=0;
if(a[miny][sx]==0)h=h+1;
if(sx<minx)h=h+1;
if(sx>k)h=0;
if(h==2)minx=sx;
}
cx=minx;
cy=miny;
}
最終更新:2015年10月23日 16:22