アットウィキロゴ

pan

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();
var a=new Array();
var b=new Array();
var life_a = new Array();
var life_b = new Array();
var area = new Array();
 
function sample(){
 
     for (s = 1; s < 11; s++) {
        a[s] = 1;
        b[s] = 100;
        life_a[s] = 100;
        life_b[s] = 100;
    }
 
     for (s = 1; s < 101; s++) {
        area[s] = 3;
    }
 
    area[1] = 1;
    area[100] = 2;
 
 
    hex();
 
 
var timer;
var delay = 100;
 
var loop = function () {
 
    move();
 
    game_a();
 
    game_b();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
}
 
function game_a(){
 
for (s = 1; s < 11; s++) {
        sx = a[s];
        var n1 = number_dir[sx] * Math.random();
        var n2 = Math.floor(n1) + 1;
        s1 = dir[sx][n2];
        h = 0;
        if (life_a[s] > 50) h = h + 1;
        if (area[s1] == 1) h = 0;
        if (h == 1) fight_a(s1);
        }
 
 
 
}
 
function game_b(){
 
for (s = 1; s < 11; s++) {
        sx = b[s];
        var n1 = number_dir[sx] * Math.random();
        var n2 = Math.floor(n1) + 1;
        s1 = dir[sx][n2];
        h = 0;
        if (life_b[s] > 50) h = h + 1;
         if (area[s1]==2) h = 0;
        if (h == 1) fight_b(s1);
        }
 
 
 
}
 
 
 
 
function fight_a(a1){
 
    if(Math.random()>0.9)area[a1] = 1;
 
}
 
function fight_b(a1){
 
    if(Math.random()>0.9)area[a1] = 2;
 
}
 
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 move(){
 
    for (s = 1; s < 11; s++) {
        sx = a[s];
        var n1 = number_dir[sx] * Math.random();
        var n2 = Math.floor(n1) + 1;
        s1 = dir[sx][n2];
        if (area[s1] == 1) sx = s1;
        a[s] = sx;
 
        }
 
        for (s = 1; s < 11; s++) {
        sx = b[s];
        var n1 = number_dir[sx] * Math.random();
        var n2 = Math.floor(n1) + 1;
        s1 = dir[sx][n2];
        if (area[s1] == 2) sx = s1;
        b[s] = sx;
 
        }
 
 
}
 
 
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 paint(){
 
 
var sub=new svgpaint();
 
str="<svg width=\"700\" height=\"700\">";
 
h = trany(30,60);
 
for(s=1;s<101;s++){
 
 
 
    for (sx = 1; sx < 7; sx++) {
        y_pol[sx] = h * y[s] + trany(30, 60 * sx);
        x_pol[sx] = 45 * x[s] + tranx(30, 60 * sx);
    }
    number_pol = 6;
    str = str + poly("blue");
 
 
      for (sx = 1; sx < 7; sx++) {
        y_pol[sx] = h * y[s] + trany(30, 60 * sx);
        x_pol[sx] = 45 * x[s] + tranx(30, 60 * sx);
    }
    number_pol = 6;
    if(area[s]==1)str = str + poly("green");
    if(area[s]==2)str = str + poly("pink");
 
 
for (sx = 1; sx < 7; sx++) {
yy1 = h * y[s] + trany(30, 60 * sx);
xx1 = 45 * x[s] + tranx(30, 60 * sx);
yy2 = h * y[s] + trany(30, 60 * sx+60);
xx2 = 45 * x[s] + tranx(30, 60 * sx+60);
str = str + sub.line(xx1, yy1, xx2, yy2, 2, "black");
}  
 
}
 
for(tx=1;tx<11;tx++){ 
s = a[tx];
for (sx = 1; sx < 7; sx++) {
        y_pol[sx] = h * y[s] + trany(30, 60 * sx);
        x_pol[sx] = 45 * x[s] + tranx(30, 60 * sx);
    }
    number_pol = 6;
    if(life_a[tx]>50)str = str + poly("red");
}
 
for(tx=1;tx<11;tx++){ 
s = b[tx];
for (sx = 1; sx < 7; sx++) {
        y_pol[sx] = h * y[s] + trany(30, 60 * sx);
        x_pol[sx] = 45 * x[s] + tranx(30, 60 * sx);
    }
    number_pol = 6;
    if(life_a[tx]>50)str = str + poly("yellow");
}
 
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;
 
}
 
 
 
function hex(){
 
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;
    }
 
}
最終更新:2015年06月18日 12:29