DJSGTPE - JavaScript-QuelltextQuelltext von djsgtpe.js |
![]() ![]() ![]() |
Dies ist die Auflistung der Datei djsgt.js,
die Objekte für die Darstellung grafischer 2D-Vektorgebilde auf HTML-Seiten bereitstellt. Diese Scripts benötigen einen DOM-Level3-Browser (Gecko (Mozilla, Netscape, Galeon), KHTML (KDE Konqueror), MSIE). Im folgenden Quelltext sind Prozedurdeklarationen rot und Kommentare grün markiert. |
![]() ![]() ![]() ![]() |
/* +---------------------------------------------------------+ | Droeppez JavaScript Pixel Emitter | | grafische Gestaltung von HTML-Seiten ueber JavaScript | | it's DHTML, baby! you know? | +---------------------------------------------------------+ | unterstuetzende Browsertypen: | | Gecko (Mozilla, Netscape 6+, Galeon, ...) | | KHTML (KDE Konqueror 3+ und andere) | | Microsoft Internet Explorer 6+ | +---------------------------------------------------------+ | (c) 2003 Ulrich Kritzner | +---------------------------------------------------------+ */ /* Der Einsatz dieser Datei in kommerziellen Projekten ist kostenpflichtig. */ /* ---------------------------------------------------------------- */ /* Darstellung */ function djsgt_FillRect(left,top,width,height) /* zeichnet einen Balken in eine Pixelsammlung */ { var element; if (typeof(this.isPE)!="number") return; element=document.createElement("div"); element.style.position="absolute"; element.style.fontSize="0px"; element.style.borderSpacing="0px"; element.style.margin="0px"; element.style.padding="0px"; element.style.minWidth=width; element.style.minHeight=height; element.style.maxWidth=width; element.style.maxHeight=height; element.style.width=width; element.style.height=height; this.element.style.overflow="hidden"; element.style.left=left; element.style.top=top; element.style.background=this.color; this.element.appendChild(element); this.Bars[this.Bars.length]=element; } function djsgt_SetXY(x,y) /* setzt den Anfangspunkt fuer Linien */ { if (typeof(this.isPE)!="number") return; this.x=Math.round(x); this.y=Math.round(y); } function djsgt_LineTo(xe,ye,thickness) /* zeichnet eine Linie in eine Pixelsammlung */ { var horz,a,b,aold,bold,adim,bdim,width,height,th,temp; xe=Math.round(xe); ye=Math.round(ye); var nxe=xe,nye=ye; thickness=Math.abs(thickness); if (thickness<1) thickness=1; if (typeof(this.isPE)!="number") return; th=Math.round(thickness/2); width=Math.abs(xe-this.x); height=Math.abs(ye-this.y); if (height>width) { horz=0; adim=ye-this.y; bdim=xe-this.x; } else { horz=1; bdim=ye-this.y; adim=xe-this.x; } if (adim<0) { temp=this.y; this.y=ye; ye=temp; temp=this.x; this.x=xe; xe=temp; adim=-adim; bdim=-bdim; } aold=0; bold=Math.round((aold/adim)*bdim); for (a=0;a<adim;a++) { b=Math.round((a/adim)*bdim); if (b!=bold) { if (horz) this.FillRect(aold+this.x-th,bold+this.y-th,a-aold-1+thickness,thickness); else this.FillRect(bold+this.x-th,aold+this.y-th,thickness,a-aold-1+thickness); bold=b; aold=a; } } if (horz) this.FillRect(aold+this.x-th,bold+this.y-th,a-aold-1+thickness,thickness); else this.FillRect(bold+this.x-th,aold+this.y-th,thickness,a-aold-1+thickness); this.x=nxe; this.y=nye; } function djsgt_i_fs_AddPoint(x,i) { x=Math.round(x); i=Math.round(i); if (i<0) return; if (i>=this.height) return; if (this.xl[i]>x) this.xl[i]=x; if (this.xr[i]<x) this.xr[i]=x; } function djsgt_internal_FillSpace(height,xmin,xmax) { var i; this.xl=new Array(); this.xr=new Array(); this.height=Math.round(height+1); this.xmin=Math.round(xmin); this.xmax=Math.round(xmax); this.AddPoint=djsgt_i_fs_AddPoint; for (i=0;i<this.height;i++) { this.xl[i]=this.xmax+1; this.xr[i]=this.xmin-1; } } function djsgt_FillPoly(x,y) /* zeichnet ein gefuelltes Polygon in eine Pixelsammlung */ { var xmin,ymin,xmax,ymax,i,j,points,width,height,a,b,aa,ba,ae,be,al,bl,horz,temp; var xl,xr,fillspace; var xa,ya,xe,ye; if ((typeof(x.length)!="number")||(typeof(y.length)!="number")) return; if ((x.length!=y.length)||(x.length<3)) return; points=x.length; xmin=x[0]; xmax=x[0]; ymin=y[0]; ymax=y[0]; for (i=1;i<points;i++) { if (x[i]>xmax) xmax=x[i]; if (x[i]<xmin) xmin=x[i]; if (y[i]>ymax) ymax=y[i]; if (y[i]<ymin) ymin=y[i]; } width=xmax-xmin+1; height=ymax-ymin+1; fillspace=new djsgt_internal_FillSpace(height,xmin,xmax); for (i=0;i<points;i++) { horz=1; j=i+1; if (j==points) j=0; aa=x[i]; ae=x[j]; ba=y[i]; be=y[j]; al=ae-aa; bl=be-ba; if (Math.abs(bl)>Math.abs(al)) { horz=0; temp=aa; aa=ba; ba=temp; temp=ae; ae=be; be=temp; temp=al; al=bl; bl=temp; } if (al<0) { al=-al; bl=-bl; temp=aa; aa=ae; ae=temp; temp=ba; ba=be; be=temp; } for (j=0;j<=Math.round(al);j++) { a=j+aa; b=(j*bl/al)+ba; if (horz) fillspace.AddPoint(a,b-ymin); else fillspace.AddPoint(b,a-ymin); } } ya=ymin; ye=ymin; ymin=Math.round(ymin); height=fillspace.height; xl=fillspace.xl; xr=fillspace.xr; xa=xl[0]; xe=xr[0]; for (i=1;i<height;i++) { ye=i+ymin; if ((xa!=xl[i])||(xe!=xr[i])) { if (xe>=xa) this.FillRect(xa-1,ya-1,xe-xa+1,ye-ya); ya=ye; xa=xl[i]; xe=xr[i]; } } if (xe>=xa) this.FillRect(xa-1,ya-1,xe-xa+1,ye-ya); } function djsgt_FillArc(xm,ym,rx,ry,alfa_a,alfa_e,n) /* Fuellt ein Tortenstueck mit n+1 Ecken */ { var x=new Array(),y=new Array(),i,alfa_diff=alfa_e-alfa_a; for (i=0;i<=n;i++) { x[i]=xm+Math.sin(alfa_a+alfa_diff/n*i)*rx; y[i]=ym-Math.cos(alfa_a+alfa_diff/n*i)*ry; } x[i]=xm; y[i]=ym; this.FillPoly(x,y); } function djsgt_SetColor(colorstyle) /* setzt den Zeichenstil des Gesamtgebildes */ { var i; if (typeof(this.isPE)!="number") return; this.color=colorstyle; for (i=0;i<this.Bars.length;i++) this.Bars[i].style.background=this.color; } /* ---------------------------------------------------------------- */ /* Konstruktor */ function DJSGTPixelEmitter(left,top,width,height,colorstyle) /* kreiert eine Pixelsammlung - nicht groessenveraenderlich - abgeschlossen (keine weiteren djsgt-Inhaltsobjekte moeglich) */ { this.Init=DJSGTObject; this.Init(left,top,width,height); this.canHaveChilds=0; this.canResize=0; this.Bars=new Array(); this.FillRect=djsgt_FillRect; this.SetXY=djsgt_SetXY; this.LineTo=djsgt_LineTo; this.FillPoly=djsgt_FillPoly; this.FillArc=djsgt_FillArc; this.SetColor=djsgt_SetColor; this.isPE=1; this.color=colorstyle; this.x=0; this.y=0; } |
![]() ![]() ![]() |
Autor: Ulrich Kritzner |