A JS that can draw lines, polygons, circles, filled on the page

xiaoxiao2021-03-06  69

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.mozopacity! = "undefined";

Function PNTDOC () {this.wnd.document.write (jg_fast? this.htmrpc (): this.htm; this.htm = ';}

Function pntcnvdom () {var x = document.createrange (); x.setstartbefore (this.cnv); x = x.createcontextualfragment (jg_fast? this.htmrpc (): this.htm); this.cnv.Appendchild (x) THIS.HTM = '';}

Function pntcnvie () {this.cnv.insertadjacenthtml ("beforeend", jg_fast? this.htmrpc (): this.htm); this.htm = ';}

Function pntcnvihtm () {this.cnv.innerhtml = this.htm; this.htm = ';}

Function PNTCNV () {this.htm = ';}

Function MKDIV (X, Y, W, H) {this.htm = '

';} function mkdivie (x, y, w, h) {THIS.HTM = '%%' this.color ';' X ';' Y ';' W ';' H ';';

Function Mkdivprt (x, y, w, h) {this.htm = '

';}

Function MklyR (X, Y, W, H) {this.htm = ' / n';}

Var regex = / %% ([^;] ); ([^;] ); ([^;] ); ([^;] ); / g; function Htmrpc () {Return this.htm.Replace (regex, '

/ n ');} Function htmprtrpc () {Return this.htm.Replace (regex,'

Function Mkovdott (Left, Top, Width, Height) {var A = Width >> 1, B = Height >> 1, Wod = Width & 1, HOD = Height & 1, CX = Left A, CY = TOP B, X = 0 , y = b, AA2 = (A * a) << 1, aa4 = aa2 << 1, bb = (b * b) << 1, st = (aa2 >> 1) * (1- (b << 1)) BB, TT = (BB >> 1) - AA2 * ((B << 1) -1), drw = true; while (y> 0) {IF (ST <0) {st = BB * ((x << 1) 3); TT = (BB << 1) * ( x);} else if (tt <0) {st = bb * ((x << 1) 3) - AA4 * (Y-1); TT = (bb << 1) * ( x) - AA2 * ((Y -) << 1) -3);} else {tt - = AA2 * (Y << 1) -3); ST - = aa4 * (- y);} if (drw) this.mkovqds (CX, CY, -X, X WOD, -Y, Y HOD , 1, 1); DRW =! Drw;}} function mkRect (x, y, w, h) {var s = this.Stroke; this.mkdiv (x, y, w, s); this.mkdiv (x w, y, s, h); this.mkdiv (x, y h, w s, s); this.mkdiv (x, y s, hs);} function mkRectdtt (x, y, w, h) {this.drawline (x, y, x w, y); this.drawline (x w, y, x w, y h); this.drawline (x, y h, x w, y h); this.drawline (x, y, x, y h);}

Function jsgfont () {this.plain = 'font-weight: Normal; this.bold =' font-weight: bold; '; this.italic =' font-style: italic; "this.italic_bold = this. Italic this.bold; this.bold_italic = this.italic_bold;} var font = new jsgfont ();

Function jsgstroke () {this.dotted = -1;} var stroke = new jsgstroke ();

Function JSGraphics (ID, WND) {this.setColor = New function ('arg', 'this.color = arg.tolowercase ();');

THIS.STSTROKE = Function (x) {this.stroke = x; if (! (× 1)) {this.drawline = mklindott; this.mkov = mkovdott; this.drawRect = mkRectd;} else if (x-1 > 0) {this.drawline = mklin2d; this.mkov = mkov2d; this.drawRect = mkRect;} else {this.drawline = mklin; this.mkov = mkov; this.drawRect = mkRect;}}; this.SetPrintable = Function (arg) {this.printable = arg; if (jg_fast) {this.mkdiv = mkdivie; this.htmrpc = arg? HTMPRTRPC: htmrpc;} else this.mkdiv = jg_n4? MKLYR: arg? mkdivprt: mkdiv;};

THIS.SETFONT = Function (FAM, SZ, STY) {this.ftfam = fam; this.ftsz = sz; this.ftsty = sty || font.plain;

This.drawpolyline = this.drawpolyline = function (x, y, s) {for (var i = 0; i

THIS.FILLRECT = Function (x, y, w, h) {this.mkdiv (x, y, w, h);};

THIS.DRAWPOLYGON = Function (x, y) {this.drawpolyline (x, y); this.drawline (x.length-1], y [x.length-1], x [x.length-1], x [0], y [0 ]);

This.drawellipse = this.drawoval = function (x, y, w, h) {THIS.MKOV (x, y, w, h);};

THIS.FLLLLLIPSE = this.FillOval = function (Left, TOP, W, H) {var A = (w - = 1) >> 1, b = (h - = 1) >> 1, WOD = (W & 1) 1, hod = (h & 1) 1, cx = left a, cy = top b, x = 0, y = b, ox = 0, OY = B, AA2 = (A * a) << 1, aa4 = aa2 << 1, bb = (b * b) << 1, st = (aa2 >> 1) * (1- (b << 1)) bb, tt = (bb >> 1) - aa2 * ((B << 1) -1), PXL, DW, DH; IF (W 1) While (Y> 0) {IF (ST <0) {ST = BB * ((x << 1) 3); TT = (BB << 1) * ( x);} else if (tt <0) {ST = BB * ((x << 1) 3) - aa4 * (Y-1 ); PXL = CX-X; DW = (x << 1) WOD; TT = (BB << 1) * ( x) - aa2 * ((Y -) << 1) -3 ); DH = OY-Y; this.mkdiv (PXL, CY-OY, DW, DH); THIS.MKDIV (PXL, CY OY-DH HOD, DW, DH); ox = x; = y; } else {tt - = aa2 * ((Y << 1) -3); ST - = aa4 * (- y);}} this.mkdiv (CX-A, CY-OY, W 1, (OY << 1) hod);}; this.fillpolygon = function (array_x, array_y) {var i; var y; var miny, maxy; var x1, y1; var x2, y2; var indef1, ind2; var inters;

VAR n = array_x.length;

IF (! n) return;

Miny = array_y [0]; MAXY = array_y [0]; for (i = 1; i

IF (array_y [i]> maxY) maxy = array_y [i];} for (y = miny; y <= maxy; y ) {var polyints = new array (); INTS = 0; for (i = 0; i Y2) {y2 = array_y [inde]; y1 = array_y [ind2]; x2 = array_x [ind1] ; x1 = array_x [ind2];} else continue; if (Y> = Y1) && (Y

Else IF && (Y> Y1) && (Y <= Y2)) Polyints [INTS ] = Math.Round ((Y-Y1) * (x2-x1) / (Y2-Y1) X1);} polyints.sort; integer_compare;

For (i = 0; i

THIS.DRAWSTRING = Function (TXT, X, Y) {this.htm = '

' txt ' ';}

THISDRAWIMAGE = Function (IMGSRC, X, Y, W, H) {this.htm = '

' ' ' ';} this.clear = function () {this.htm ="; if (this.cnv) this.cnv.innerHTML = THIS.DEFHTM;};

THIS.MKOVQDS = Function (CX, CY, XL, XR, YT, YB, W, H) {THIS.MKDIV (XR CX, YT CY, W, H); this.mkdiv (XR CX, YB CY, W, H); this.mkdiv (XL CX, YB CY, W, H); this.mkdiv (XL CX, YT CY, W, H);

THIS.SETSTROKE (1); this.SetFont ('Verdana, Geneva, Helvetica, Sans-Serif', String.Fromcharcode (0x31, 0x32, 0x70, 0x78), Font.Plain); this.color = '# 000000'; THIS.HTM = ''; this.Wnd = Wnd || WINDOW;

IF (! (jg_ie || jg_dom || jg_ihtm)) chkdhtm (); if (TypeOf ID! = 'string' ||! id) this.paint = pntdoc; else {this.cnv = document.all? (this. Wnd.document.all [ID] || null): Document.getElementByid? (this.wnd.document.getlementByid (ID) || null): null; this.defhtm = (this.cnv && this.cnv.innerhtml) this.cnv.innerhtml: ''; this.paint = jg_dom? PNTCNVDOM: JG_IE? PNTCNVIE: JG_IHTM? PNTCNVIHTM: PNTCNV;

This.SetPrintable (false);

Function Integer_compare (x, y) {RETURN (x y) * 1);}

转载请注明原文地址:https://www.9cbs.com/read-88897.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.033, SQL: 9