http://expert.csdn.net/Expert/topic/1665/1665572.xml
对画直线部分做了一点纯学术意义上的优化呵呵,并且把基本的绘画函数分离出来了。
文件名:
emu_draw.js
//-----------------------------------------------------------------------
// emu's dhtml painting functions
function drawLine(x0,y0,x1,y1,color){
x0 = Math.round(x0);
x1 = Math.round(x1);
y0 = Math.round(y0);
y1 = Math.round(y1);
var rs = "";
if (y0 == y1){ //»ºáÏß
if (x0>x1){var t=x0;x0=x1;x1=t}
rs = "
1<p class="emuH" style='top:"+y0+";left:"+x0+";background-color:"+color+"; width:"+Math.abs(x1-x0)+"'></p>
";
}
else if (x0 == x1){ //»ÊúÏß
if (y0>y1){var t=y0;y0=y1;y1=t}
rs = "
1<p class="emuW" style='top:"+y0+";left:"+x0+";background-color:"+color+";height:"+Math.abs(y1-y0)+"'></p>
";
}
else{
var lx = x1-x0;
var ly = y1-y0;
if (Math.abs(lx)>Math.abs(ly)){
if (ly<0){
var t=x0;x0=x1;x1=t;
t=y0;y0=y1;y1=t;
lx = -lx;
ly = -ly;
}
var dx = lx/ly;
rs = new Array(ly);
for (var i=0;i
1<ly;i++){ (dx="" if="" left,width;="" var="">0){
2left = Math.round(i*dx);
3width = Math.round((i+1)*dx)-left;
4left += x0;
5if (width+left>x1) width = x1-left;
6}else{
7left = Math.round((i+1)*dx);
8width = Math.round((i)*dx)-left;
9left += x0;
10if (left<x1) +(y0+i)+";left:"+left+";width:"+width+";background-color:"+color+"'="" left="x1;" rs[i]="<p class=emuH style='top:" width="width+left-x1;" {="" }=""></x1)>";
11}
12}else{
13if (lx<0){
14var t=x0;x0=x1;x1=t;
15t=y0;y0=y1;y1=t;
16lx = -lx;
17ly = -ly;
18}
19var dy = ly/lx;
20rs = new Array(lx);
21for (var i=0;i<lx;i++){ (dy="" if="" top,height;="" var="">0){
22top = Math.round(i*dy);
23height = Math.round((i+1)*dy)-top;
24top += y0;
25if (height+top>y1) height = y1-top;
26}else{
27top = Math.round((i+1)*dy);
28height = Math.round((i)*dy)-top;
29top += y0;
30if (top<y1) +top+";left:"+(x0+i)+";height:"+height+";background-color:"+color+"'="" height="height+top-y1;" rs[i]="<p class=emuW style='top:" top="y1;" {="" }=""></y1)>";
31}
32}
33rs = rs.join("");
34}
35return rs
36}
37function drawRectangle(x0,y0,x1,y1,color,title)
38{
39if (x0 == x1 ¦ ¦ y0 == y1) return;
40if (x0>x1) {var t=x0;x0=x1;x1=t}
41if (y0>y1) {var t=y0;y0=y1;y1=t}
42return "<table style='top:"+y0+";left:"+x0+";position:absolute' title="+title+"><td bgcolor="+color+" height="+(y1-y0)+" width="+(x1-x0)+"> </td></table>";
43}
44function outText(x0,y0,text,fontSize,color){
45return "<p style='top:"+y0+";left:"+x0+";position:absolute;color:"+color+";font-size:"+fontSize+"'>"+text+"</p>";
46}
47var points = new Array(1000);
48function drawPie(x0,y0,radius,startAngle,endAngle,color){
49if (points.length<radius<<2) (maxx<x)="" (minx="" (var="" ;="" arc="" endangle="endAngle*Math.PI/180;" for="" get="" i="startAngle;i<endAngle;i+=step){" if="" lines="" maxx="x;" points="" points.length="radius<<2;" points[pointslength++]="[x,y];" pointslength="0;" startangle="startAngle*Math.PI/180;" step="1/radius;" var="" x="Math.round(Math.sin(i)*radius);" y="Math.round(Math.cos(i)*radius)">x) minX=x;
50if (maxY<y) (miny="" if="" maxy="y;">y) minY=y;
51}
52
53// get radius points
54var dx1=Math.sin(startAngle)*radius;
55var dy1=Math.cos(startAngle)*radius;
56var dx2=Math.sin(endAngle)*radius;
57var dy2=Math.cos(endAngle)*radius;
58var L = Math.sqrt(dx1*dx1+dy1*dy1);
59var stepx1 = dx1/L , stepy1 = dy1/L ,stepx2 = dx2/L , stepy2 = dy2/L ;
60for (var i=0;i<l;i+=.99){ (dx="" dx="maxX-minX+1;" dy="maxY-minY+1;" if="" points[pointslength++]="[Math.round(stepx2*i),Math.round(stepy2*i)]" var="" }="">dy){
61lines = new Array(dy);
62for (var i=pointsLength-1;i>-1;i--){
63var p0 = points[i];
64var px = p0[0];
65var y = p0[1]-minY;
66if (lines[y]){
67if (lines
68\---------------------------------------------------------------
69
70顶
71\---------------------------------------------------------------
72
73我只有看的份了.
74\---------------------------------------------------------------
75
76请问大侠,
77对于现实中的应用有何以意呢?
78可否举下例子先?
79\---------------------------------------------------------------
80
81大虾的学问太精深,我要好好的研究。
82\---------------------------------------------------------------
83
84分
85\---------------------------------------------------------------
86
87复杂,收藏
88\---------------------------------------------------------------
89
90结贴时通知一声哦,此乃珍品,应入精华.
91\---------------------------------------------------------------
92
93呵呵
94\---------------------------------------------------------------
95
96再收……
97看看会不会再有update……
98\---------------------------------------------------------------
99
100偶像……:)
101\---------------------------------------------------------------
102
103可惜csdn不能上传图片。不然就有直观的了。
104\---------------------------------------------------------------
105
106up
107\---------------------------------------------------------------
108
109收藏!:)
110\---------------------------------------------------------------
111
112绘图?
113为什么不用vml语言?
114\---------------------------------------------------------------
115
116emu做得好东西啊,收藏之
117\---------------------------------------------------------------
118
119果然是大侠!不错,收藏!
120\---------------------------------------------------------------
121
122在此学习也能得分啊!一举两得啊!
123\---------------------------------------------------------------
124
125嘿嘿……在我的ie5.0下面报错。ie版本:5.00.2920.0000
126日文win2000下的自带ie,没有升级过。
127\---------------------------------------------------------------
128
129好啊,
130\---------------------------------------------------------------
131
132好,留着</l;i+=.99){></y)></radius<<2)></lx;i++){></ly;i++){>