otokoisan

<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();
 
function sample(){
 
 
 
tx=0; 
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
y[tx]=s;
x[tx]=sx;
c[tx]="red";
}}
 
 
 
var timer;
var delay = 300;
 
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<26;s++){
h=0;
if(x[s]==x1)h=h+1;
if(y[s]==y1)h=h+1;
if(h==2)sxs=s;
c[s]="red";
}
 
if(sxs>0)m=sxs;
c[m]="green";
 
 
 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<26;tx++){
str=str+rect(50*x[tx],50*y[tx],50,50,c[tx]);
}
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
 
 
 
 
</script>
最終更新:2018年06月03日 03:59