var x = new Array();
var y = new Array();
var dir = new Array();
var number_dir = new Array();
var x_pol = new Array();
var y_pol = new Array();
function sample(){
for(t=1;t<101;t++){
dir[t] = new Array();
}
tx = 0;
for (s = 1; s < 6; s++) {
for (sx = 1; sx < 11; sx++) {
tx = tx + 1;
x[tx] = 2 * s - 1;
y[tx] = 2 * sx - 1;
}
}
for (s = 1; s < 6; s++) {
for (sx = 1; sx < 11; sx++) {
tx = tx + 1;
x[tx] = 2 * s ;
y[tx] = 2 * sx;
}
}
for(s=1;s<101;s++){
tx=0;
x1=x[s];
y1=y[s]+2;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
x1=x[s];
y1=y[s]-2;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
x1=x[s]+1;
y1=y[s]-1;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
x1=x[s]+1;
y1=y[s]+1;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
x1=x[s]-1;
y1=y[s]+1;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
x1=x[s]-1;
y1=y[s]-1;
sx = search(x1, y1);
if (sx > 0) tx = tx + 1;
if (sx > 0) dir[s][tx] =sx;
number_dir[s] = tx;
}
paint();
}
function tranx(le1,th1){
x1 = le1*Math.cos(th1 * Math.PI / 180);
return x1;
}
function trany(le1,th1){
y1 = le1*Math.sin(th1 * Math.PI / 180);
return y1;
}
function poly(col){
var str,data;
var s;
data="";
for(s=1;s<number_pol;s++){
data=data+x_pol[s]+","+y_pol[s]+",";
}
s=number_pol;
data=data+x_pol[s]+","+y_pol[s];
str="<polygon fill="+chopx(col)+" points="+chopx(data)+"/>";
return str;
}
function chopx(str){
var strx;
strx="\""+str+"\"";
return strx;
}
function paint(){
str="<svg width=\"500\" height=\"500\">";
h = trany(20,60);
for(s=1;s<101;s++){
for (sx = 1; sx < 7; sx++) {
y_pol[sx] = h * y[s] + trany(20, 60 * sx);
x_pol[sx] = 30 * x[s] + tranx(20, 60 * sx);
}
number_pol = 6;
str = str + poly("red");
}
str = str + "</svg>";
$("#memo").html(str);
}
function search(x1,y1){
var s,sx,h;
sx=0;
for (s = 1; s < 101; s++) {
h = 0;
if (x[s] == x1) h = h + 1;
if (y[s] == y1) h = h + 1;
if (h == 2) sx = s;
}
return sx;
}
最終更新:2015年06月17日 07:34