# 求一个思路,请高手帮帮忙

newmcz 2003-11-23 10:41:34

<html>
<head>
<title>JavaScript绘图</title>
<script language="JavaScript">
IE4 = ! (navigator.appVersion.charAt(0) < "4" || navigator.appName == "Netscape")

var xo=0
var yo=0
var Ox = -1
var Oy = -1

var rad = Math.PI/180
var maxY = 400
var color = "black"

function print(str) {
document.write(str)
}

function orgY(y) {
return maxY-y
}
function outPlot(x,y,w,h) {
print('<span style="position:absolute;left:'+x+';top:'+y+';height:'+h+';width:'+w+';font-size:1px;background-color:'+color+'"></span>')
}

function Plot(x,y) {
outPlot(x,y,1,1)
if(Ox>=0 || Oy>=0) {
ShowLine(Ox,Oy,x-Ox,y-Oy)
}
Ox = x
Oy = y
}

function ShowLine(x,y,w,h) {
if(w<0) {
x += w
w = Math.abs(w)
}
if(h<0) {
y += h
h = Math.abs(h)
}
if(w<1) w=1
if(h<1) h=1
outPlot(x,y,Math.round(w),Math.round(h))
}

function LineTo(x,y) {
Line(xo,yo,x,y)
}

function sign(n) {
if(n>0)
return 1
if(n<0)
return -1
return n
}

function Line(x1,y1,x2,y2) {
x2 = Math.round(x2)
y2 = Math.round(y2)
xo = x2
yo = y2
y1 = orgY(y1)
y2 = orgY(y2)
var str = ""
var i=0

var x = x1
var y = y1
dx = Math.abs(x2-x1)
dy = Math.abs(y2-y1)
s1 = sign(x2-x1)
s2 = sign(y2-y1)

if(dx==0 || dy==0) {
ShowLine(x1,y1,x2-x1,y2-y1)
return
}

if(dx>dy) {
temp = dx
dx = dy
dy = temp
key = 1
}else
key = 0
e = 2*dy-dx

for(i=0;i<dx;i++) {
px = 0
py = 0
Plot(x,y)
while(e>=0) {
if(key==1) {
x += s1
px += s1
}else {
y += s2
py += s2
}
e = e-2*dx
}
if(key==1)
y += s2
else
x += s1
e = e+2*dy
}
}

function MoveTo(x,y) {
Ox = Oy = -1
xo = Math.round(x)
yo = Math.round(y)
}
</script>
</head>
<body>
<script>
if(IE4) {
var oColor = "red"
MoveTo(300,-100)
LineTo(700,-100)
LineTo(500,300)
LineTo(300,-100)
MoveTo(700,-100)
LineTo(730,-30)
LineTo(500,300)

MoveTo(350,0)
LineTo(650,0)
LineTo(673,53)

MoveTo(400,100)
LineTo(600,100)
LineTo(621,131)

MoveTo(450,200)
LineTo(550,200)
LineTo(562,215)

}else {
document.write("<p> </p><table bgcolor=#FF0000><tr><td><font color=#FFFF00>对不起！您的浏览器不能支持该页的某些功能，请换用IE4.0以上版本的浏览器！谢谢！</font></td></tr></table>")
}
</script>
</body>
</html>
...全文
51 11 打赏 收藏 举报

11 条回复

http://www.lshdic.com/wenzhang.asp?str=Vml&page=1

• 打赏
• 举报

newmcz 2003-11-24
up
• 打赏
• 举报

newmcz 2003-11-23

<HTML xmlns:v>
<HEAD>
<META http-equiv="Content-Type" content="text/html; Charset=gb2312">
<TITLE></TITLE>
<STYLE>
v\:*{behavior:url(#default#VML);} //这里声明了v作为VML公用变量
</STYLE>
</HEAD>
<BODY>
<v:line strokecolor='black' from='40,350' to='200,20'/>
<v:line strokecolor='black' from='40,350' to='360,350'/>
<v:line strokecolor='black' from='200,20' to='360,350'/>

<v:line strokecolor='black' from='200,20' to='200,350'/>
<v:line strokecolor='black' from='120,185' to='280,185'/>
</BODY>
</HTML>
• 打赏
• 举报

sunicom 2003-11-23
gz
• 打赏
• 举报

newmcz 2003-11-23

• 打赏
• 举报

supere 2003-11-23

• 打赏
• 举报

newmcz 2003-11-23

• 打赏
• 举报

supere 2003-11-23

• 打赏
• 举报

newmcz 2003-11-23

• 打赏
• 举报

supere 2003-11-23

• 打赏
• 举报

newmcz 2003-11-23
<HTML xmlns:v>
<HEAD>
<META http-equiv="Content-Type" content="text/html; Charset=gb2312">
<TITLE></TITLE>
<STYLE>
v\:*{behavior:url(#default#VML);} //这里声明了v作为VML公用变量
</STYLE>
</HEAD>
<BODY>
<v:line strokecolor='black' from='40,350' to='200,20'/>
<v:line strokecolor='black' from='40,350' to='360,350'/>
<v:line strokecolor='black' from='200,20' to='360,350'/>

<v:line strokecolor='black' from='200,20' to='200,350'/>
<v:line strokecolor='black' from='120,185' to='280,185'/>

<v:polyline title="" fillcolor="#000000" points=" 40,350 120,185 280,185 360,350"> </v:polyline>
<v:polyline title="" fillcolor="#654321" points=" 120,185 280,185 200,20"> </v:polyline>

</BODY>
</HTML>
• 打赏
• 举报

8.6w+

Web 开发 JavaScript

2003-11-23 10:41