## CSDN博客

### JavaScript图形库

JavaScript图形库

VisualSW

http://www.walterzorn.com/scripts/wz_jsgraphics.zip

/*

=====================================================================================

======================================================================

*/

var LineColor="#000000";

var LineWidth=3;

var ArrowBegin=true;

var ArrowEnd=true;

/*

======================================================================

*/

/*

======================================================================

======================================================================

*/

this.setArrowWidth = function(x)

{

}

this.setArrowAngle = function(x)

{

x=x>90?45:x;

x=x<0?45:x;

}

this.setLineWidth = function(x)

{

LineWidth=x;

}

this.setLineColor = function(x)

{

LineColor=x;

}

this.setArrowBegin = function(x)

{

ArrowBegin=x;

}

this.setArrowEnd = function(x)

{

ArrowEnd=x;

}

{

this.setColor(LineColor);

this.setStroke(LineWidth);

var dx,dy;

dx=Math.abs(beginX-endX);

dy=Math.abs(beginY-endY);

var LineSlope;//直线斜率(弧度)

LineSlope=Math.atan(dx/dy);

//求出中距每点的坐标

var tmpLine;

//起点中点

var BeginCenterX;

var BeginCenterY;

//终点中点

var EndCenterX;

var EndCenterY;

if(ArrowBegin)

{

//绘制起点三角形

//Begin

BeginCenterX=beginX+tmpLine*Math.sin(LineSlope);

BeginCenterY=beginY+tmpLine*Math.cos(LineSlope);

//定义起点三角形的三个顶点

var BeginX1,BeginY1;

var BeginX2,BeginY2;

var BeginX3,BeginY3;

BeginX1=beginX;

BeginY1=beginY;

var XBeginpoints = new Array(BeginX1,BeginX2,BeginX3);

var YBeginpoints = new Array(BeginY1,BeginY2,BeginY3);

this.fillPolygon(XBeginpoints, YBeginpoints);

//End

}

else

{

BeginCenterX=beginX;

BeginCenterY=beginY;

}

if(ArrowEnd)

{

//绘制终点三角形

//Begin

EndCenterX=endX-tmpLine*Math.sin(LineSlope);

EndCenterY=endY-tmpLine*Math.cos(LineSlope);

//定义终点三角形的三个顶点

var EndX1,EndY1;

var EndX2,EndY2;

var EndX3,EndY3;

EndX1=endX;

EndY1=endY;

var XEndpoints = new Array(EndX1,EndX2,EndX3);

var YEndpoints = new Array(EndY1,EndY2,EndY3);

this.fillPolygon(XEndpoints, YEndpoints);

//End

}

else

{

EndCenterX=endX;

EndCenterY=endY;

}

//绘制中心线

this.drawLine(BeginCenterX,BeginCenterY,EndCenterX,EndCenterY);

}

this.drawFlowLine = function(beginX,beginY,endX,endY,beginText,endText)

{

var TextX;

var TextY;

TextX=beginX+20;

TextY=beginY;

this.drawString(beginText,TextX,TextY);

}

<HTML>

<title>DHTML JavaScript Tooltips</title>

<script language="javascript" src="./Graphics.js"></script>

<script language="javascript">

var jg = new jsGraphics();

jg.setArrowWidth(4);

jg.setArrowAngle(20);

jg.setLineWidth(2);

jg.setLineColor("Blue");

jg.drawFlowLine(10,10,200,200,"Line1");

jg.setLineColor("Red");

jg.setArrowBegin(false);

jg.drawFlowLine(110,10,300,200,"Line2","End");

jg.setLineColor("Green");

jg.setArrowBegin(true);

jg.setArrowEnd(false);

jg.drawFlowLine(210,10,400,200,"","Line3");

jg.setArrowEnd(true);

jg.setArrowAngle(15);

jg.drawFlowLine(310,10,500,200,"","Line4");

jg.setArrowAngle(30);

jg.drawFlowLine(410,10,600,200,"","Line5");

jg.setLineWidth(10)

jg.drawFlowLine(410,10,600,200,"","Line5");

jg.setStroke(10)

jg.drawLine(10,300,400,500);

jg.paint();

</script>

<meta http-equiv="expires" content="0">

<body>

</body>

</HTML>

This program is free software;

you can redistribute it and/or modify it under the terms of the

either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY;

without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License

at http://www.gnu.org/copyleft/gpl.html for more details.

0 0