// 6
A js (Part 1) that allows you to draw lines, polygon, circles, fills, and other functions at Will on the page)
VaR jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz,
Jg_n4 = (document. Layers & typeof document. classes! = "Undefined ");
Function chkdhtm (X, I)
{
X = Document. Body | NULL;
Jg_ie = x & typeof X. insertadjacenthtml! = "Undefined ";
Jg_dom = (X &&! Jg_ie &&
Typeof X. appendchild! = "Undefined "&&
Typeof document. createRange! = "Undefined "&&
Typeof (I = Document. createRange (). setstartbefore! = "Undefined "&&
Typeof I. createcontextualfragment! = "Undefined ");
Jg_ihtm =! Jg_ie &&! Jg_dom & X & typeof X. innerhtml! = "Undefined ";
Jg_fast = jg_ie & document. All &&! Window. Opera;
Jg_moz = jg_dom & typeof X. style. Invalid opacity! = "Undefined ";
}
Function pntdoc ()
{
This.wnd.doc ument. Write (jg_fast? This.htm RPC (): this.htm );
This.htm = '';
}
Function pntcnvdom ()
{
VaR x = Document. createRange ();
X. setstartbefore (this. NV );
X = x. createcontextualfragment (jg_fast? This.htm RPC (): this.htm );
This. NV. appendchild (X );
This.htm = '';
}
Function pntcnvie ()
{
This. NV. insertadjacenthtml ("beforeend", jg_fast? This.htm RPC (): this.htm );
This.htm = '';
}
Function pntcnvihtm ()
{
This. NV. innerhtml + = this.htm;
This.htm = '';
}
Function pntnv ()
{
This.htm = '';
}
Function mkdiv (X, Y, W, H)
{
This.htm + = '<Div style = "position: absolute;' +
'Left: '+ x + 'px;' +
'Top: '+ Y + 'px;' +
'Width: '+ W + 'px;' +
'Height: '+ H + 'px;' +
'Clip: rect (0, '+ W + 'px,' + H + 'px, 0); '+
'Background-color: '+ this. color +
(! Jg_moz? '; Overflow: Den den': '') +
'; "> <// Div> ';
}
Function mkdivie (X, Y, W, H)
{
This.htm + = '%' + this. color + ';' + x + ';' + Y + ';' + W + ';' + H + ';';
}
Function mkdivprt (X, Y, W, H)
{
This.htm + = '<Div style = "position: absolute;' +
'Border-left: '+ W + 'px solid' + this. color +'; '+
'Left: '+ x + 'px;' +
'Top: '+ Y + 'px;' +
'Width: 0px; '+
'Height: '+ H + 'px;' +
'Clip: rect (0, '+ W + 'px,' + H + 'px, 0); '+
'Background-color: '+ this. color +
(! Jg_moz? '; Overflow: Den den': '') +
'; "> <// Div> ';
}
Function mklyr (X, Y, W, H)
{
This.htm + = '<layer' +
'Left = "'+ x +'" '+
'Top = "'+ Y +'" '+
'Width = "'+ W +'" '+
'Height = "'+ H +'" '+
'Bgcolor = "'+ this. color +'"> </layer>/N ';
}
VaR RegEx =/% ([^;] +); ([^;] +); ([^;] +); ([^;] + ); ([^;] +);/g;
Function htmrpc ()
{
Return this.htm. Replace (
RegEx,
'<Div style = "overflow: hidden; position: absolute; Background-color:' +
'$1; left: $2; top: $3; width: $4; Height: $5 "> </div>/N ');
}
Function htmprtrpc ()
{
Return this.htm. Replace (
RegEx,
'<Div style = "overflow: hidden; position: absolute; Background-color:' +
'$1; left: $2; top: $3; width: $4; Height: $5; border-left: $ 4px solid $1 "> </div>/N ');
}
Function mklin (x1, Y1, X2, Y2)
{
If (x1> x2)
{
VaR _ X2 = x2;
VaR _ y2 = Y2;
X2 = x1;
Y2 = Y1;
X1 = _ X2;
Y1 = _ Y2;
}
VaR dx = x2-x1, dy = math. Abs (y2-y1 ),
X = x1, y = Y1,
Yincr = (Y1> Y2 )? -1: 1;
If (dx> = Dy)
{
VaR Pr = Dy <1,
Pru = Pr-(DX <1 ),
P = Pr-dx,
Ox = X;
While (dx --)> 0)
{
++ X;
If (P> 0)
{
This. mkdiv (OX, Y, X-ox, 1 );
Y + = yincr;
P + = Pru;
Ox = X;
}
Else P + = Pr;
}
This. mkdiv (OX, Y, x2-ox + 1, 1 );
}
Else
{
VaR Pr = DX <1,
Pru = Pr-(dy <1 ),
P = Pr-dy,
Oy = y;
If (Y2 <= Y1)
{
While (dy --)> 0)
{
If (P> 0)
{
This. mkdiv (x ++, Y, 1, oy-y + 1 );
Y + = yincr;
P + = Pru;
Oy = y;
}
Else
{
Y + = yincr;
P + = Pr;
}
}
This. mkdiv (X2, Y2, 1, oy-y2 + 1 );
}
Else
{
While (dy --)> 0)
{
Y + = yincr;
If (P> 0)
{
This. mkdiv (x ++, oy, 1, Y-Oy );
P + = Pru;
Oy = y;
}
Else P + = Pr;
}
This. mkdiv (X2, oy, 1, y2-oy + 1 );
}
}
}
Function mklin2d (x1, Y1, X2, Y2)
{
If (x1> x2)
{
VaR _ X2 = x2;
VaR _ y2 = Y2;
X2 = x1;
Y2 = Y1;
X1 = _ X2;
Y1 = _ Y2;
}
VaR dx = x2-x1, dy = math. Abs (y2-y1 ),
X = x1, y = Y1,
Yincr = (Y1> Y2 )? -1: 1;
VaR S = This. Stroke;
If (dx> = Dy)
{
If (S-3> 0)
{
VaR _ S = (S * DX * Math. SQRT (1 + dy * dy/(dx * dx)-DX-(S> 1) * dy)/dx;
_ S = (! S-4 )? Math. Ceil (_ s): Math. Round (_ s) + 1;
}
Else VaR _ S = s;
VaR ad = math. Ceil (S/2 );
VaR Pr = Dy <1,
Pru = Pr-(DX <1 ),
P = Pr-dx,
Ox = X;
While (dx --)> 0)
{
++ X;
If (P> 0)
{
This. mkdiv (OX, Y, X-ox + AD, _ s );
Y + = yincr;
P + = Pru;
Ox = X;
}
Else P + = Pr;
}
This. mkdiv (OX, Y, x2-ox + AD + 1, _ s );
}
Else
{
If (S-3> 0)
{
VaR _ S = (S * dy * Math. SQRT (1 + dx * dx/(dy * Dy)-(S> 1) * DX-dy)/dy;
_ S = (! S-4 )? Math. Ceil (_ s): Math. Round (_ s) + 1;
}
Else VaR _ S = s;
VaR ad = math. Round (S/2 );
VaR Pr = DX <1,
Pru = Pr-(dy <1 ),
P = Pr-dy,
Oy = y;
If (Y2 <= Y1)
{
++ Ad;
While (dy --)> 0)
{
If (P> 0)
{
This. mkdiv (x ++, Y, _ s, oy-y + AD );
Y + = yincr;
P + = Pru;
Oy = y;
}
Else
{
Y + = yincr;
P + = Pr;
}
}
This. mkdiv (X2, Y2, _ s, oy-y2 + AD );
}
Else
{
While (dy --)> 0)
{
Y + = yincr;
If (P> 0)
{
This. mkdiv (x ++, oy, _ s, Y-oy + AD );
P + = Pru;
Oy = y;
}
Else P + = Pr;
}
This. mkdiv (X2, oy, _ s, y2-oy + AD + 1 );
}
}
}
Function mklindott (x1, Y1, X2, Y2)
{
If (x1> x2)
{
VaR _ X2 = x2;
VaR _ y2 = Y2;
X2 = x1;
Y2 = Y1;
X1 = _ X2;
Y1 = _ Y2;
}
VaR dx = x2-x1, dy = math. Abs (y2-y1 ),
X = x1, y = Y1,
Yincr = (Y1> Y2 )? -1: 1,
Drw = true;
If (dx> = Dy)
{
VaR Pr = Dy <1,
Pru = Pr-(DX <1 ),
P = Pr-DX;
While (dx --)> 0)
{
If (drw) This. mkdiv (X, Y, 1, 1 );
Drw =! Drw;
If (P> 0)
{
Y + = yincr;
P + = Pru;
}
Else P + = Pr;
++ X;
}
If (drw) This. mkdiv (X, Y, 1, 1 );
}
Else
{
VaR Pr = DX <1,
Pru = Pr-(dy <1 ),
P = Pr-dy;
While (dy --)> 0)
{
If (drw) This. mkdiv (X, Y, 1, 1 );
Drw =! Drw;
Y + = yincr;
If (P> 0)
{
++ X;
P + = Pru;
}
Else P + = Pr;
}
If (drw) This. mkdiv (X, Y, 1, 1 );
}
}
Function mkov (left, top, width, height)
{
VaR A = width> 1, B = height> 1,
Wod = width & 1, Hod = (Height & 1) + 1,
Cx = left + A, Cy = Top + B,
X = 0, y = B,
Ox = 0, oy = B,
AA = (A * A) <1, BB = (B * B) <1,
St = (AA> 1) * (1-(B <1) + BB,
Tt = (BB> 1)-aa * (B <1)-1 ),
W, h;
While (Y> 0)
{
If (ST <0)
{
St + = BB * (x <1) + 3 );
Tt + = (BB <1) * (++ X );
}
Else if (TT <0)
{
St + = BB * (x <1) + 3)-(AA <1) * (Y-1 );
Tt + = (BB <1) * (++ X)-aa * (y --) <1)-3 );
W = x-ox;
H = Oy-y;
If (W & 2 & H & 2)
{
This. mkovqds (CX, Cy,-x + 2, Ox + wod,-Oy, oy-1 + Hod, 1, 1 );
This. mkovqds (CX, Cy,-x + 1, X-1 + wod,-Y-1, Y + Hod, 1, 1 );
}
Else this. mkovqds (CX, Cy,-x + 1, Ox + wod,-Oy, oy-H + Hod, W, H );
Ox = X;
Oy = y;
}
Else
{
TT-= AA * (Y <1)-3 );
St-= (AA <1) * (-- y );
}
}
This. mkdiv (CX-a, cy-Oy, A-ox + 1, (Oy <1) + hod );
This. mkdiv (cx + ox + wod, cy-Oy, A-ox + 1, (Oy <1) + hod );
}