
var jg = new jsGraphics("myCanvas");
var jg2 = new jsGraphics("myCanvas2");

var hflip=0;
var vflip=0;
var lines=0;
var rotate=0;
var x1,y1;
var rad;

var hflip2=0;
var vflip2=0;
var rotate2=0;
var x12,y12;
var rad2;
color="white";



function myDrawFunction(x,y,rad)
{

 if (lines) {
  jg.setColor(color);

  if (rotate==0) {
   if (hflip==0) {
    if (vflip==0) {
     jg.drawLine(x-rad*0.618, y-rad, x+rad, y-rad);
     jg.drawLine(x+rad, y-rad, x+rad, y);
    } else {
     jg.drawLine(x-rad*0.618, y, x+rad, y);
     jg.drawLine(x+rad, y, x+rad, y+rad);
    }
   } else {
    if (vflip==0) {
     jg.drawLine(x-rad, y-rad, x+rad*0.618, y-rad);
     jg.drawLine(x+rad*0.618, y-rad, x+rad*0.618, y);
    } else {
     jg.drawLine(x-rad, y, x+rad*0.618, y);
     jg.drawLine(x+rad*0.618, y, x+rad*0.618, y+rad);
    }
   } 
  } else {
   if (hflip==0) {
    if (vflip==0) {
     jg.drawLine(x-rad, y-rad, x-rad, y+rad*0.618);
     jg.drawLine(x-rad, y+rad*0.618, x, y+rad*0.618);
    } else {
     jg.drawLine(x-rad, y-rad*0.618, x-rad, y+rad);
     jg.drawLine(x-rad, y+rad, x, y+rad);
    }
   } else {
    if (vflip==0) {
     jg.drawLine(x, y-rad, x, y+rad*0.618);
     jg.drawLine(x, y+rad*0.618, x+rad, y+rad*0.618);
    } else {
     jg.drawLine(x, y-rad*0.618, x, y+rad);
     jg.drawLine(x, y+rad, x+rad, y+rad);
    }
   }
  }
 }

 if (rotate==0) {
  if (hflip==0) {
   if (vflip==0) {
    x1=x;y1=y;
    Collapse(1);Collapse(4);Collapse(3);Collapse(2);Collapse(1);Collapse(4);Collapse(3);
    jg.paint();
   } else {
    x1=x;y1=y;
    Collapse(2);Collapse(3);Collapse(4);Collapse(1);Collapse(2);Collapse(3);Collapse(4);
    jg.paint();
   }
  } else {
   if (vflip==0) {
    x1=x;y1=y;
    Collapse(4);Collapse(1);Collapse(2);Collapse(3);Collapse(4);Collapse(1);Collapse(2);
    jg.paint();
   } else {
    x1=x;y1=y;
    Collapse(3);Collapse(2);Collapse(1);Collapse(4);Collapse(3);Collapse(2);Collapse(1);
    jg.paint();
   }
  }
 } else {
  if (hflip==0) {
   if (vflip==0) {
    x1=x;y1=y;
    Collapse(4);Collapse(3);Collapse(2);Collapse(1);Collapse(4);Collapse(3);Collapse(2);
    jg.paint();
   } else {
    x1=x;y1=y;
    Collapse(3);Collapse(4);Collapse(1);Collapse(2);Collapse(3);Collapse(4);Collapse(1);
    jg.paint();
   }
  } else {
   if ((hflip==1)&&(vflip==0)) {
    x1=x;y1=y;
    Collapse(1);Collapse(2);Collapse(3);Collapse(4);Collapse(1);Collapse(2);Collapse(3);
    jg.paint();
   } else {
    x1=x;y1=y;
    Collapse(2);Collapse(1);Collapse(4);Collapse(3);Collapse(2);Collapse(1);Collapse(4);
    jg.paint();
   }
  }
 }

}

 function Collapse(RLUD)
 { 
  var rad2;
  rad2=rad*2;
  jg.setColor(color);
  jg.drawEllipse(x1-rad,y1-rad,rad2,rad2, RLUD);
  if (lines) {jg.setColor(color)};

  if (RLUD==1) {
   if (hflip==0) {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1, y1-rad)};y1=y1-rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1+rad, y1)};x1=x1+rad*0.382};
   } else {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1+rad, y1)};x1=x1+rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1, y1-rad)};y1=y1-rad*0.382};
   }

  } else
  if (RLUD==2) {
   if (hflip==0) {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1+rad, y1)};x1=x1+rad*0.382} 
    else {if (lines) {jg.drawLine(x1, y1, x1, y1+rad)};y1=y1+rad*0.382};
   } else {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1, y1+rad)};y1=y1+rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1+rad, y1)};x1=x1+rad*0.382};
   }

  } else
  if (RLUD==3) {
   if (hflip==0) {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1, y1+rad)};y1=y1+rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1-rad, y1)};x1=x1-rad*0.382};
   } else {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1-rad, y1)};x1=x1-rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1, y1+rad)};y1=y1+rad*0.382};
   }

  } else
  if (RLUD==4) {
   if (hflip==0) {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1-rad, y1)};x1=x1-rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1, y1-rad)};y1=y1-rad*0.382};
   } else {
    if (vflip==0) {if (lines) {jg.drawLine(x1, y1, x1, y1-rad)};y1=y1-rad*0.382}
    else {if (lines) {jg.drawLine(x1, y1, x1-rad, y1)};x1=x1-rad*0.382};
   }
  }
 
  rad=rad*0.618;
 } 


function redraw()
{
 if (rotate==0) {
  if (grid.offsetHeight>(grid.offsetWidth)/1.618) {rad=(grid.offsetWidth)/1.618} 
  else {rad=grid.offsetHeight}
  if (hflip==0) {
   if (vflip==0) {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+rad*0.618,           table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+grid.offsetHeight,rad);}
   else {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+rad*0.618,                    table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+grid.offsetHeight-rad,rad);}
  } else {
   if (vflip==0) {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+rad,                 table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+grid.offsetHeight,rad);}
   else {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+rad,                          table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+grid.offsetHeight-rad,rad);}
  }

 } else {
  if (grid.offsetWidth>(grid.offsetHeight)/1.618) {rad=(grid.offsetHeight)/1.618} 
  else {rad=grid.offsetWidth}
  if (hflip==0) {
   if (vflip==0) {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+grid.offsetWidth,    table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+rad,rad);}
   else {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+grid.offsetWidth,             table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+rad*0.618,rad);}
  } else {
   if (vflip==0) {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+grid.offsetWidth-rad,table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+rad,rad);}
   else {myDrawFunction(table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+grid.offsetWidth-rad,         table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+rad*0.618,rad);}
  }
 }
}

function redraw2()
{
var tx,ty,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,t,ttx,tty;
 jg2.setColor(color);
 if (rotate2==0) {
  if (grid.offsetHeight>(grid.offsetWidth)/1.618) {rad2=(grid.offsetWidth)/1.618} 
  else {rad2=grid.offsetHeight}
  ttx=table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft;
  tty=table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop;
  if (hflip2==0) {
   if (vflip2==0) {
    tx1=ttx;
    ty1=tty+grid.offsetHeight-rad2;
    tx2=ttx+rad2*1.618;
    ty2=tty+grid.offsetHeight;
    tx3=ttx+rad2*1.618;
    ty3=tty+grid.offsetHeight-rad2;
    tx4=ttx+rad2;
    ty4=tty+grid.offsetHeight;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx1,ty1,tx3,ty3);
     jg2.drawLine(tx3,ty3,tx2,ty2);
    }
   } else {
    tx1=ttx;
    ty1=tty+grid.offsetHeight;
    tx2=ttx+rad2*1.618;
    ty2=tty+grid.offsetHeight-rad2;
    tx3=ttx+rad2*1.618;
    ty3=tty+grid.offsetHeight;
    tx4=ttx+rad2;
    ty4=tty+grid.offsetHeight-rad2;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx2-rad2*1.618,ty2,tx2,ty2);
     jg2.drawLine(tx2,ty2,tx3,ty3);
    }
   }
  } else {
   if (vflip2==0) {
    tx1=ttx+rad2*1.618;
    ty1=tty+grid.offsetHeight-rad2;
    tx2=ttx;
    ty2=tty+grid.offsetHeight;
    tx3=ttx;
    ty3=tty+grid.offsetHeight-rad2;
    tx4=ttx+rad2*0.618;
    ty4=tty+grid.offsetHeight;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx3,ty3,tx1,ty1);
     jg2.drawLine(tx1,ty1,tx1,ty1+rad2);
    }
   }
   else {
    tx1=ttx+rad2*1.618;
    ty1=tty+grid.offsetHeight;
    tx2=ttx;
    ty2=tty+grid.offsetHeight-rad2;
    tx3=ttx;
    ty3=tty+grid.offsetHeight;
    tx4=ttx+rad2*0.618;
    ty4=tty+grid.offsetHeight-rad2;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx2,ty2,tx1,ty2);
     jg2.drawLine(tx1,ty2,tx1,ty1);
    }
   }
  }

 } else {
  if (grid.offsetWidth>(grid.offsetHeight)/1.618) {rad2=(grid.offsetHeight)/1.618} 
  else {rad2=grid.offsetWidth}
  ttx=table1.offsetLeft+tr1.offsetLeft+document.all.lefttd.offsetWidth+grid.offsetLeft+grid.offsetWidth;
  tty=table1.offsetTop+tr1.offsetTop+document.all.toptd.offsetHeight+grid.offsetTop+grid.offsetHeight;
  if (hflip2==0) {
   if (vflip2==0) {
    tx1=ttx-rad2;
    ty1=tty;
    tx2=ttx;
    ty2=tty-rad2*1.618;
    tx3=ttx-rad2;
    ty3=tty-rad2*1.618;
    tx4=ttx;
    ty4=tty-rad2;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx1,ty1,tx3,ty3);
     jg2.drawLine(tx3,ty3,tx2,ty2);
    }
   }
   else {
    tx1=ttx-rad2;
    ty1=tty-rad2*1.618;
    tx2=ttx;
    ty2=tty;
    tx3=ttx-rad2;
    ty3=tty;
    tx4=ttx;
    ty4=tty-rad2*0.618;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx1,ty1,tx3,ty3);
     jg2.drawLine(tx1,ty1,tx2,ty1);
    }
   }
  } else {
   if (vflip2==0) {
    tx1=ttx;
    ty1=tty;
    tx2=ttx-rad2;
    ty2=tty-rad2*1.618;
    tx3=ttx;
    ty3=tty-rad2*1.618;
    tx4=ttx-rad2;
    ty4=tty-rad2;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx2,ty2,tx2,ty1);
     jg2.drawLine(tx2,ty2,tx3,ty3);
    }
   }
   else {
    tx1=ttx;
    ty1=tty-rad2*1.618;
    tx2=ttx-rad2;
    ty2=tty;
    tx3=ttx;
    ty3=tty;
    tx4=ttx-rad2;
    ty4=tty-rad2*0.618;
    t=(((tx4-tx3)*(ty1-ty3)-(ty4-ty3)*(tx1-tx3))/((ty4-ty3)*(tx2-tx1)-(tx4-tx3)*(ty2-ty1)));
    tx=tx1+t*(tx2-tx1);
    ty=ty1+t*(ty2-ty1);
    jg2.drawLine(tx1,ty1,tx2,ty2);
    jg2.drawLine(tx3,ty3,tx,ty);

    if (lines) {
     jg2.drawLine(tx2,ty1,tx2,ty2);
     jg2.drawLine(tx2,ty1,tx1,ty1);
    }
   }
  }
 }
 jg2.paint();
}

