var x = new Array();
var y = new Array();
var link_a = new Array();
var link_b = new Array();
function sample() {
y_body = 200;
x_body = 250;
th_body = 90;
len_body = 100;
th_head = 90;
len_head = 50;
len_sh_r = 30;
th_sh_r = 0;
th_sh_l = 180;
len_sh_l = 30;
th_hand_r = 300;
len_hand_r = 50;
len_hand_l = 50;
th_hand_l = 250;
th_finger_r = 270;
len_finger_r = 30;
len_finger_l = 30;
th_finger_l = 270;
th_hip_r = 0;
len_hip_r = 20;
len_hip_l = 20;
th_hip_l = 180;
th_leg_r = 270;
len_leg_r = 40;
len_leg_l = 40;
th_leg_l = 270;
th_foot_r = 270;
len_foot_r = 40;
len_foot_l = 40;
th_foot_l = 270;
link_a[1] = 1;
link_b[1] = 2;
link_a[2] = 2;
link_b[2] = 3;
link_a[3] = 2;
link_b[3] = 4;
link_a[4] = 2;
link_b[4] = 5;
link_a[5] = 4;
link_b[5] = 6;
link_a[6] = 5;
link_b[6] = 7;
link_a[7] = 6;
link_b[7] = 8;
link_a[8] = 7;
link_b[8] = 9;
link_a[9] = 1;
link_b[9] = 10;
link_a[10] = 1;
link_b[10] = 11;
link_a[11] = 10;
link_b[11] = 12;
link_a[12] = 11;
link_b[12] = 13;
link_a[13] = 12;
link_b[13] = 14;
link_a[14] = 13;
link_b[14] = 15;
var timer;
var delay = 1000;
var loop = function () {
y_body = y_body + 10;
if (y_body > 200) y_body = 100;
change();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function change() {
x[1] = x_body;
y[1] = y_body;
x[2] = x[1] + tranx(len_body, th_body);
y[2] = y[1] + trany(len_body, th_body);
x[3] = x[2] + tranx(len_head, th_head);
y[3] = y[2] + trany(len_head, th_head);
x[4] = x[2] + tranx(len_sh_l, th_sh_l);
y[4] = y[2] + trany(len_sh_l, th_sh_l);
x[5] = x[2] + tranx(len_sh_r, th_sh_r);
y[5] = y[2] + trany(len_sh_r, th_sh_r);
x[6] = x[4] + tranx(len_hand_l, th_hand_l);
y[6] = y[4] + trany(len_hand_l, th_hand_l);
x[7] = x[5] + tranx(len_hand_r, th_hand_r);
y[7] = y[5] + trany(len_hand_r, th_hand_r);
x[8] = x[6] + tranx(len_finger_l, th_finger_l);
y[8] = y[6] + trany(len_finger_l, th_finger_l);
x[9] = x[7] + tranx(len_finger_r, th_finger_r);
y[9] = y[7] + trany(len_finger_r, th_finger_r);
x[10] = x[1] + tranx(len_hip_l, th_hip_l);
y[10] = y[1] + trany(len_hip_l, th_hip_l);
x[11] = x[1] + tranx(len_hip_r, th_hip_r);
y[11] = y[1] + trany(len_hip_r, th_hip_r);
x[12] = x[10] + tranx(len_leg_l, th_leg_l);
y[12] = y[10] + trany(len_leg_l, th_leg_l);
x[13] = x[11] + tranx(len_leg_r, th_leg_r);
y[13] = y[11] + trany(len_leg_r, th_leg_r);
x[14] = x[12] + tranx(len_foot_l, th_foot_l);
y[14] = y[12] + trany(len_foot_l, th_foot_l);
x[15] = x[13] + tranx(len_foot_r, th_foot_r);
y[15] = y[13] + trany(len_foot_r, th_foot_r);
}
function paint() {
var sub = new svgpaint();
str = "<svg width=\"500\" height=\"500\">";
str = str + sub.rect(0, 0, 500, 500, "blue");
for (s = 1; s < 16; s++) {
str = str + sub.circle(x[s], 500 - y[s], 10, "red");
}
for (s = 1; s < 15; s++) {
s1 = link_a[s];
s2 = link_b[s];
str = str + sub.line(x[s1], 500 - y[s1], x[s2], 500 - y[s2], 3, "red");
}
str = str + "</svg>";
$("#memo").html(str);
}
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;
}
最終更新:2015年06月20日 16:51