<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var x=new Array();
var y=new Array();
var c=new Array();
var m;
function sample(){
tx=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
tx=tx+1;
y[tx]=s;
x[tx]=sx;
c[tx]=1;
}}
var timer;
var delay = 100;
m=1;
var loop = function () {
dx=1;
if(Math.random()>0.5)dx=-1;
dy=1;
if(Math.random()>0.5)dy=-1;
x1=x[m]+dx;
y1=y[m]+dy;
sxs=0;
for(s=1;s<101;s++){
h=0;
if(x1==x[s])h=h+1;
if(y1==y[s])h=h+1;
if(h==2)sxs=s;
}
if(sxs>0)m=sxs;
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function rect(x1,y1,w1,h1,col){
var strx;
strx="<rect x="+chop(x1)+"\" y="+chop(y1)+"\" width="+chop(w1);
strx=strx+"\" height="+chop(h1)+" fill="+chop(col)+"/>";
return strx;
}
function chop(strp){
var strx;
strx="\""+strp+"\"";
return strx;
}
function paint(){
str="<svg width=\"500\" height=\"500\">";
for(tx=1;tx<101;tx++){
if(c[tx]==1)str=str+rect(30*x[tx],30*y[tx],30,30,"green");
}
str=str+rect(30*x[m],30*y[m],30,30,"red");
str=str+"</svg>";
$("#memo").html(str);
}
</script>
最終更新:2018年06月04日 11:42