一个可以在页面上随意画线、多边形、圆,填充等功能的js

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 += '

  1<div style="position:absolute;'+   
  2'left:' + x + 'px;'+   
  3'top:' + y + 'px;'+   
  4'width:' + w + 'px;'+   
  5'height:' + h + 'px;'+   
  6'clip:rect(0,'+w+'px,'+h+'px,0);'+   
  7'background-color:' + this.color +   
  8(!jg_moz? ';overflow:hidden' : '')+   
  9';">&lt;\/div&gt;';   
 10} 
 11
 12  
 13function mkDivIe(x, y, w, h)   
 14{   
 15this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';';   
 16} 
 17
 18  
 19function mkDivPrt(x, y, w, h)   
 20{   
 21this.htm += '<div style="position:absolute;'+   
 22'border-left:' + w + 'px solid ' + this.color + ';'+   
 23'left:' + x + 'px;'+   
 24'top:' + y + 'px;'+   
 25'width:0px;'+   
 26'height:' + h + 'px;'+   
 27'clip:rect(0,'+w+'px,'+h+'px,0);'+   
 28'background-color:' + this.color +   
 29(!jg_moz? ';overflow:hidden' : '')+   
 30';">&lt;\/div&gt;';   
 31} 
 32
 33  
 34function mkLyr(x, y, w, h)   
 35{   
 36this.htm += '<layer '+="" 'bgcolor="' + this.color + '" 'height="' + h + '" 'left="' + x + '" 'top="' + y + '" 'width="' + w + '">&lt;\/layer&gt;\n';   
 37} 
 38
 39  
 40var regex = /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;   
 41function htmRpc()   
 42{   
 43return this.htm.replace(   
 44regex,   
 45'<div style="overflow:hidden;position:absolute;background-color:'+   
 46'$1;left:$2;top:$3;width:$4;height:$5"></div>\n');   
 47} 
 48
 49  
 50function htmPrtRpc()   
 51{   
 52return this.htm.replace(   
 53regex,   
 54'<div style="overflow:hidden;position:absolute;background-color:'+   
 55'$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1"></div>\n');   
 56} 
 57
 58  
 59function mkLin(x1, y1, x2, y2)   
 60{   
 61if (x1 &gt; x2)   
 62{   
 63var _x2 = x2;   
 64var _y2 = y2;   
 65x2 = x1;   
 66y2 = y1;   
 67x1 = _x2;   
 68y1 = _y2;   
 69}   
 70var dx = x2-x1, dy = Math.abs(y2-y1),   
 71x = x1, y = y1,   
 72yIncr = (y1 &gt; y2)? -1 : 1; 
 73
 74if (dx &gt;= dy)   
 75{   
 76var pr = dy&lt;&lt;1,   
 77pru = pr - (dx&lt;&lt;1),   
 78p = pr-dx,   
 79ox = x;   
 80while ((dx--) &gt; 0)   
 81{   
 82++x;   
 83if (p &gt; 0)   
 84{   
 85this.mkDiv(ox, y, x-ox, 1);   
 86y += yIncr;   
 87p += pru;   
 88ox = x;   
 89}   
 90else p += pr;   
 91}   
 92this.mkDiv(ox, y, x2-ox+1, 1);   
 93} 
 94
 95else   
 96{   
 97var pr = dx&lt;&lt;1,   
 98pru = pr - (dy&lt;&lt;1),   
 99p = pr-dy,   
100oy = y;   
101if (y2 &lt;= y1)   
102{   
103while ((dy--) &gt; 0)   
104{   
105if (p &gt; 0)   
106{   
107this.mkDiv(x++, y, 1, oy-y+1);   
108y += yIncr;   
109p += pru;   
110oy = y;   
111}   
112else   
113{   
114y += yIncr;   
115p += pr;   
116}   
117}   
118this.mkDiv(x2, y2, 1, oy-y2+1);   
119}   
120else   
121{   
122while ((dy--) &gt; 0)   
123{   
124y += yIncr;   
125if (p &gt; 0)   
126{   
127this.mkDiv(x++, oy, 1, y-oy);   
128p += pru;   
129oy = y;   
130}   
131else p += pr;   
132}   
133this.mkDiv(x2, oy, 1, y2-oy+1);   
134}   
135}   
136} 
137
138  
139function mkLin2D(x1, y1, x2, y2)   
140{   
141if (x1 &gt; x2)   
142{   
143var _x2 = x2;   
144var _y2 = y2;   
145x2 = x1;   
146y2 = y1;   
147x1 = _x2;   
148y1 = _y2;   
149}   
150var dx = x2-x1, dy = Math.abs(y2-y1),   
151x = x1, y = y1,   
152yIncr = (y1 &gt; y2)? -1 : 1; 
153
154var s = this.stroke;   
155if (dx &gt;= dy)   
156{   
157if (s-3 &gt; 0)   
158{   
159var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s&gt;&gt;1)*dy) / dx;   
160_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;   
161}   
162else var _s = s;   
163var ad = Math.ceil(s/2); 
164
165var pr = dy&lt;&lt;1,   
166pru = pr - (dx&lt;&lt;1),   
167p = pr-dx,   
168ox = x;   
169while ((dx--) &gt; 0)   
170{   
171++x;   
172if (p &gt; 0)   
173{   
174this.mkDiv(ox, y, x-ox+ad, _s);   
175y += yIncr;   
176p += pru;   
177ox = x;   
178}   
179else p += pr;   
180}   
181this.mkDiv(ox, y, x2-ox+ad+1, _s);   
182} 
183
184else   
185{   
186if (s-3 &gt; 0)   
187{   
188var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s&gt;&gt;1)*dx-dy) / dy;   
189_s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;   
190}   
191else var _s = s;   
192var ad = Math.round(s/2); 
193
194var pr = dx&lt;&lt;1,   
195pru = pr - (dy&lt;&lt;1),   
196p = pr-dy,   
197oy = y;   
198if (y2 &lt;= y1)   
199{   
200++ad;   
201while ((dy--) &gt; 0)   
202{   
203if (p &gt; 0)   
204{   
205this.mkDiv(x++, y, _s, oy-y+ad);   
206y += yIncr;   
207p += pru;   
208oy = y;   
209}   
210else   
211{   
212y += yIncr;   
213p += pr;   
214}   
215}   
216this.mkDiv(x2, y2, _s, oy-y2+ad);   
217}   
218else   
219{   
220while ((dy--) &gt; 0)   
221{   
222y += yIncr;   
223if (p &gt; 0)   
224{   
225this.mkDiv(x++, oy, _s, y-oy+ad);   
226p += pru;   
227oy = y;   
228}   
229else p += pr;   
230}   
231this.mkDiv(x2, oy, _s, y2-oy+ad+1);   
232}   
233}   
234} 
235
236  
237function mkLinDott(x1, y1, x2, y2)   
238{   
239if (x1 &gt; x2)   
240{   
241var _x2 = x2;   
242var _y2 = y2;   
243x2 = x1;   
244y2 = y1;   
245x1 = _x2;   
246y1 = _y2;   
247}   
248var dx = x2-x1, dy = Math.abs(y2-y1),   
249x = x1, y = y1,   
250yIncr = (y1 &gt; y2)? -1 : 1,   
251drw = true;   
252if (dx &gt;= dy)   
253{   
254var pr = dy&lt;&lt;1,   
255pru = pr - (dx&lt;&lt;1),   
256p = pr-dx;   
257while ((dx--) &gt; 0)   
258{   
259if (drw) this.mkDiv(x, y, 1, 1);   
260drw = !drw;   
261if (p &gt; 0)   
262{   
263y += yIncr;   
264p += pru;   
265}   
266else p += pr;   
267++x;   
268}   
269if (drw) this.mkDiv(x, y, 1, 1);   
270} 
271
272else   
273{   
274var pr = dx&lt;&lt;1,   
275pru = pr - (dy&lt;&lt;1),   
276p = pr-dy;   
277while ((dy--) &gt; 0)   
278{   
279if (drw) this.mkDiv(x, y, 1, 1);   
280drw = !drw;   
281y += yIncr;   
282if (p &gt; 0)   
283{   
284++x;   
285p += pru;   
286}   
287else p += pr;   
288}   
289if (drw) this.mkDiv(x, y, 1, 1);   
290}   
291} 
292
293  
294function mkOv(left, top, width, height)   
295{   
296var a = width&gt;&gt;1, b = height&gt;&gt;1,   
297wod = width&amp;1, hod = (height&amp;1)+1,   
298cx = left+a, cy = top+b,   
299x = 0, y = b,   
300ox = 0, oy = b,   
301aa = (a*a)&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
302st = (aa&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
303tt = (bb&gt;&gt;1) - aa*((b&lt;&lt;1)-1),   
304w, h;   
305while (y &gt; 0)   
306{   
307if (st &lt; 0)   
308{   
309st += bb*((x&lt;&lt;1)+3);   
310tt += (bb&lt;&lt;1)*(++x);   
311}   
312else if (tt &lt; 0)   
313{   
314st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
315tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
316w = x-ox;   
317h = oy-y;   
318if (w&amp;2 &amp;&amp; h&amp;2)   
319{   
320this.mkOvQds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1);   
321this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);   
322}   
323else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);   
324ox = x;   
325oy = y;   
326}   
327else   
328{   
329tt -= aa*((y&lt;&lt;1)-3);   
330st -= (aa&lt;&lt;1)*(--y);   
331}   
332}   
333this.mkDiv(cx-a, cy-oy, a-ox+1, (oy&lt;&lt;1)+hod);   
334this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy&lt;&lt;1)+hod);   
335}   
336  
337  
338  
339  
340  
341function mkOv2D(left, top, width, height)   
342{   
343var s = this.stroke;   
344width += s-1;   
345height += s-1;   
346var a = width&gt;&gt;1, b = height&gt;&gt;1,   
347wod = width&amp;1, hod = (height&amp;1)+1,   
348cx = left+a, cy = top+b,   
349x = 0, y = b,   
350aa = (a*a)&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
351st = (aa&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
352tt = (bb&gt;&gt;1) - aa*((b&lt;&lt;1)-1); 
353
354if (s-4 &lt; 0 &amp;&amp; (!(s-2) || width-51 &gt; 0 &amp;&amp; height-51 &gt; 0))   
355{   
356var ox = 0, oy = b,   
357w, h,   
358pxl, pxr, pxt, pxb, pxw;   
359while (y &gt; 0)   
360{   
361if (st &lt; 0)   
362{   
363st += bb*((x&lt;&lt;1)+3);   
364tt += (bb&lt;&lt;1)*(++x);   
365}   
366else if (tt &lt; 0)   
367{   
368st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
369tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
370w = x-ox;   
371h = oy-y; 
372
373if (w-1)   
374{   
375pxw = w+1+(s&amp;1);   
376h = s;   
377}   
378else if (h-1)   
379{   
380pxw = s;   
381h += 1+(s&amp;1);   
382}   
383else pxw = h = s;   
384this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);   
385ox = x;   
386oy = y;   
387}   
388else   
389{   
390tt -= aa*((y&lt;&lt;1)-3);   
391st -= (aa&lt;&lt;1)*(--y);   
392}   
393}   
394this.mkDiv(cx-a, cy-oy, s, (oy&lt;&lt;1)+hod);   
395this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy&lt;&lt;1)+hod);   
396} 
397
398else   
399{   
400var _a = (width-((s-1)&lt;&lt;1))&gt;&gt;1,   
401_b = (height-((s-1)&lt;&lt;1))&gt;&gt;1,   
402_x = 0, _y = _b,   
403_aa = (_a*_a)&lt;&lt;1, _bb = (_b*_b)&lt;&lt;1,   
404_st = (_aa&gt;&gt;1)*(1-(_b&lt;&lt;1)) + _bb,   
405_tt = (_bb&gt;&gt;1) - _aa*((_b&lt;&lt;1)-1), 
406
407pxl = new Array(),   
408pxt = new Array(),   
409_pxb = new Array();   
410pxl[0] = 0;   
411pxt[0] = b;   
412_pxb[0] = _b-1;   
413while (y &gt; 0)   
414{   
415if (st &lt; 0)   
416{   
417st += bb*((x&lt;&lt;1)+3);   
418tt += (bb&lt;&lt;1)*(++x);   
419pxl[pxl.length] = x;   
420pxt[pxt.length] = y;   
421}   
422else if (tt &lt; 0)   
423{   
424st += bb*((x&lt;&lt;1)+3) - (aa&lt;&lt;1)*(y-1);   
425tt += (bb&lt;&lt;1)*(++x) - aa*(((y--)&lt;&lt;1)-3);   
426pxl[pxl.length] = x;   
427pxt[pxt.length] = y;   
428}   
429else   
430{   
431tt -= aa*((y&lt;&lt;1)-3);   
432st -= (aa&lt;&lt;1)*(--y);   
433} 
434
435if (_y &gt; 0)   
436{   
437if (_st &lt; 0)   
438{   
439_st += _bb*((_x&lt;&lt;1)+3);   
440_tt += (_bb&lt;&lt;1)*(++_x);   
441_pxb[_pxb.length] = _y-1;   
442}   
443else if (_tt &lt; 0)   
444{   
445_st += _bb*((_x&lt;&lt;1)+3) - (_aa&lt;&lt;1)*(_y-1);   
446_tt += (_bb&lt;&lt;1)*(++_x) - _aa*(((_y--)&lt;&lt;1)-3);   
447_pxb[_pxb.length] = _y-1;   
448}   
449else   
450{   
451_tt -= _aa*((_y&lt;&lt;1)-3);   
452_st -= (_aa&lt;&lt;1)*(--_y);   
453_pxb[_pxb.length-1]--;   
454}   
455}   
456} 
457
458var ox = 0, oy = b,   
459_oy = _pxb[0],   
460l = pxl.length,   
461w, h;   
462for (var i = 0; i &lt; l; i++)   
463{   
464if (typeof _pxb[i] != "undefined")   
465{   
466if (_pxb[i] &lt; _oy || pxt[i] &lt; oy)   
467{   
468x = pxl[i];   
469this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);   
470ox = x;   
471oy = pxt[i];   
472_oy = _pxb[i];   
473}   
474}   
475else   
476{   
477x = pxl[i];   
478this.mkDiv(cx-x+1, cy-oy, 1, (oy&lt;&lt;1)+hod);   
479this.mkDiv(cx+ox+wod, cy-oy, 1, (oy&lt;&lt;1)+hod);   
480ox = x;   
481oy = pxt[i];   
482}   
483}   
484this.mkDiv(cx-a, cy-oy, 1, (oy&lt;&lt;1)+hod);   
485this.mkDiv(cx+ox+wod, cy-oy, 1, (oy&lt;&lt;1)+hod);   
486}   
487} 
488
489  
490function mkOvDott(left, top, width, height)   
491{   
492var a = width&gt;&gt;1, b = height&gt;&gt;1,   
493wod = width&amp;1, hod = height&amp;1,   
494cx = left+a, cy = top+b,   
495x = 0, y = b,   
496aa2 = (a*a)&lt;&lt;1, aa4 = aa2&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
497st = (aa2&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
498tt = (bb&gt;&gt;1) - aa2*((b&lt;&lt;1)-1),   
499drw = true;   
500while (y &gt; 0)   
501{   
502if (st &lt; 0)   
503{   
504st += bb*((x&lt;&lt;1)+3);   
505tt += (bb&lt;&lt;1)*(++x);   
506}   
507else if (tt &lt; 0)   
508{   
509st += bb*((x&lt;&lt;1)+3) - aa4*(y-1);   
510tt += (bb&lt;&lt;1)*(++x) - aa2*(((y--)&lt;&lt;1)-3);   
511}   
512else   
513{   
514tt -= aa2*((y&lt;&lt;1)-3);   
515st -= aa4*(--y);   
516}   
517if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);   
518drw = !drw;   
519}   
520}   
521  
522  
523  
524  
525  
526  
527  
528function mkRect(x, y, w, h)   
529{   
530var s = this.stroke;   
531this.mkDiv(x, y, w, s);   
532this.mkDiv(x+w, y, s, h);   
533this.mkDiv(x, y+h, w+s, s);   
534this.mkDiv(x, y+s, s, h-s);   
535} 
536
537  
538function mkRectDott(x, y, w, h)   
539{   
540this.drawLine(x, y, x+w, y);   
541this.drawLine(x+w, y, x+w, y+h);   
542this.drawLine(x, y+h, x+w, y+h);   
543this.drawLine(x, y, x, y+h);   
544} 
545
546  
547function jsgFont()   
548{   
549this.PLAIN = 'font-weight:normal;';   
550this.BOLD = 'font-weight:bold;';   
551this.ITALIC = 'font-style:italic;';   
552this.ITALIC_BOLD = this.ITALIC + this.BOLD;   
553this.BOLD_ITALIC = this.ITALIC_BOLD;   
554}   
555var Font = new jsgFont(); 
556
557  
558function jsgStroke()   
559{   
560this.DOTTED = -1;   
561}   
562var Stroke = new jsgStroke(); 
563
564  
565function jsGraphics(id, wnd)   
566{   
567this.setColor = new Function('arg', 'this.color = arg.toLowerCase();'); 
568
569this.setStroke = function(x)   
570{   
571this.stroke = x;   
572if (!(x+1))   
573{   
574this.drawLine = mkLinDott;   
575this.mkOv = mkOvDott;   
576this.drawRect = mkRectDott;   
577}   
578else if (x-1 &gt; 0)   
579{   
580this.drawLine = mkLin2D;   
581this.mkOv = mkOv2D;   
582this.drawRect = mkRect;   
583}   
584else   
585{   
586this.drawLine = mkLin;   
587this.mkOv = mkOv;   
588this.drawRect = mkRect;   
589}   
590}; 
591
592  
593this.setPrintable = function(arg)   
594{   
595this.printable = arg;   
596if (jg_fast)   
597{   
598this.mkDiv = mkDivIe;   
599this.htmRpc = arg? htmPrtRpc : htmRpc;   
600}   
601else this.mkDiv = jg_n4? mkLyr : arg? mkDivPrt : mkDiv;   
602}; 
603
604  
605this.setFont = function(fam, sz, sty)   
606{   
607this.ftFam = fam;   
608this.ftSz = sz;   
609this.ftSty = sty || Font.PLAIN;   
610}; 
611
612  
613this.drawPolyline = this.drawPolyLine = function(x, y, s)   
614{   
615for (var i=0 ; i<x.length-1 )="" -="1)" ;="" =="" a="(w" function(left,="" function(x,="" h)="" h);="" i++="" this.drawellipse="this.drawOval" this.drawline(x[i],="" this.drawline(x[x.length-1],="" this.drawpolygon="function(x," this.drawpolyline(x,="" this.fillellipse="this.fillOval" this.fillrect="function(x," this.mkdiv(x,="" this.mkov(x,="" top,="" var="" w,="" x[0],="" x[i+1],="" y)="" y);="" y,="" y[0]);="" y[i+1]);="" y[i],="" y[x.length-1],="" {="" };="">&gt;1, b = (h -= 1)&gt;&gt;1,   
616wod = (w&amp;1)+1, hod = (h&amp;1)+1,   
617cx = left+a, cy = top+b,   
618x = 0, y = b,   
619ox = 0, oy = b,   
620aa2 = (a*a)&lt;&lt;1, aa4 = aa2&lt;&lt;1, bb = (b*b)&lt;&lt;1,   
621st = (aa2&gt;&gt;1)*(1-(b&lt;&lt;1)) + bb,   
622tt = (bb&gt;&gt;1) - aa2*((b&lt;&lt;1)-1),   
623pxl, dw, dh;   
624if (w+1) while (y &gt; 0)   
625{   
626if (st &lt; 0)   
627{   
628st += bb*((x&lt;&lt;1)+3);   
629tt += (bb&lt;&lt;1)*(++x);   
630}   
631else if (tt &lt; 0)   
632{   
633st += bb*((x&lt;&lt;1)+3) - aa4*(y-1);   
634pxl = cx-x;   
635dw = (x&lt;&lt;1)+wod;   
636tt += (bb&lt;&lt;1)*(++x) - aa2*(((y--)&lt;&lt;1)-3);   
637dh = oy-y;   
638this.mkDiv(pxl, cy-oy, dw, dh);   
639this.mkDiv(pxl, cy+oy-dh+hod, dw, dh);   
640ox = x;   
641oy = y;   
642}   
643else   
644{   
645tt -= aa2*((y&lt;&lt;1)-3);   
646st -= aa4*(--y);   
647}   
648}   
649this.mkDiv(cx-a, cy-oy, w+1, (oy&lt;&lt;1)+hod);   
650}; 
651
652this.fillPolygon = function(array_x, array_y)   
653{   
654var i;   
655var y;   
656var miny, maxy;   
657var x1, y1;   
658var x2, y2;   
659var ind1, ind2;   
660var ints; 
661
662var n = array_x.length; 
663
664if (!n) return; 
665
666  
667miny = array_y[0];   
668maxy = array_y[0];   
669for (i = 1; i &lt; n; i++)   
670{   
671if (array_y[i] &lt; miny)   
672miny = array_y[i]; 
673
674if (array_y[i] &gt; maxy)   
675maxy = array_y[i];   
676}   
677for (y = miny; y &lt;= maxy; y++)   
678{   
679var polyInts = new Array();   
680ints = 0;   
681for (i = 0; i &lt; n; i++)   
682{   
683if (!i)   
684{   
685ind1 = n-1;   
686ind2 = 0;   
687}   
688else   
689{   
690ind1 = i-1;   
691ind2 = i;   
692}   
693y1 = array_y[ind1];   
694y2 = array_y[ind2];   
695if (y1 &lt; y2)   
696{   
697x1 = array_x[ind1];   
698x2 = array_x[ind2];   
699}   
700else if (y1 &gt; y2)   
701{   
702y2 = array_y[ind1];   
703y1 = array_y[ind2];   
704x2 = array_x[ind1];   
705x1 = array_x[ind2];   
706}   
707else continue; 
708
709if ((y &gt;= y1) &amp;&amp; (y &lt; y2))   
710polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1); 
711
712else if ((y == maxy) &amp;&amp; (y &gt; y1) &amp;&amp; (y &lt;= y2))   
713polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);   
714}   
715polyInts.sort(integer_compare); 
716
717for (i = 0; i &lt; ints; i+=2)   
718{   
719w = polyInts[i+1]-polyInts[i]   
720this.mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1);   
721}   
722}   
723}; 
724
725  
726this.drawString = function(txt, x, y)   
727{   
728this.htm += '<div style="position:absolute;white-space:nowrap;'+   
729'left:' + x + 'px;'+   
730'top:' + y + 'px;'+   
731'font-family:' + this.ftFam + ';'+   
732'font-size:' + this.ftSz + ';'+   
733'color:' + this.color + ';' + this.ftSty + '">'+   
734txt +   
735'&lt;\/div&gt;';   
736} 
737
738  
739this.drawImage = function(imgSrc, x, y, w, h)   
740{   
741this.htm += '<div style="position:absolute;'+   
742'left:' + x + 'px;'+   
743'top:' + y + 'px;'+   
744'width:' + w + ';'+   
745'height:' + h + ';">'+   
746'<img height="' + h + '" src="' + imgSrc + '" width="' + w + '"/>'+   
747'&lt;\/div&gt;';   
748} 
749
750  
751this.clear = function()   
752{   
753this.htm = "";   
754if (this.cnv) this.cnv.innerHTML = this.defhtm;   
755}; 
756
757  
758this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h)   
759{   
760this.mkDiv(xr+cx, yt+cy, w, h);   
761this.mkDiv(xr+cx, yb+cy, w, h);   
762this.mkDiv(xl+cx, yb+cy, w, h);   
763this.mkDiv(xl+cx, yt+cy, w, h);   
764}; 
765
766this.setStroke(1);   
767this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN);   
768this.color = '#000000';   
769this.htm = '';   
770this.wnd = wnd || window; 
771
772if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM();   
773if (typeof id != 'string' || !id) this.paint = pntDoc;   
774else   
775{   
776this.cnv = document.all? (this.wnd.document.all[id] || null)   
777: document.getElementById? (this.wnd.document.getElementById(id) || null)   
778: null;   
779this.defhtm = (this.cnv &amp;&amp; this.cnv.innerHTML)? this.cnv.innerHTML : '';   
780this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv;   
781} 
782
783this.setPrintable(false);   
784} 
785
786function integer_compare(x,y)   
787{   
788return (x &lt; y) ? -1 : ((x &gt; y)*1);   
789}</div></div></x.length-1></layer></div></div>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus