39,083
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<svg height="500" width="500">
<!--<circle id="circle" cx="50" cy="50" r="40" stroke="black" stroke-width="1" fill="white"/>-->
<polygon id="polygon1" points="0,0 0,0 0,0" style="fill:white;stroke:black;stroke-width:1" />
<polygon id="polygon2" points="0,0 0,0 0,0" style="fill:white;stroke:black;stroke-width:1" />
<polygon id="polygon3" points="0,0 0,0 0,0" style="fill:white;stroke:black;stroke-width:1" />
<polygon id="polygon4" points="0,0 0,0 0,0" style="fill:white;stroke:black;stroke-width:1" />
<polygon id="polygon5" points="0,0 0,0 0,0" style="fill:white;stroke:black;stroke-width:1" />
<line id="line1" x1="0" y1="0" x2="200" y2="200" style="stroke:silver;stroke-width:1" />
<line id="line2" x1="0" y1="0" x2="200" y2="200" style="stroke:silver;stroke-width:1" />
<line id="line3" x1="0" y1="0" x2="200" y2="200" style="stroke:silver;stroke-width:1" />
</svg>
<script>
function setPol(){
var x=200,y=10,l=200,_x,_y;
var h = Math.sqrt(Math.pow(l,2) - Math.pow(l/2,2));
$("#polygon1").attr("points",x + "," + y + " " + (x+(l/2)) +"," + (y+h) + " " + (x-(l/2)) +"," + (y+h));
var y0 = (3*y + 2*h)/3;
$("#line1").attr("x1",x).attr("y1",y0).attr("x2",x).attr("y2",y);
$("#line2").attr("x1",x).attr("y1",y0).attr("x2",x+(l/2)).attr("y2",y+h);
$("#line3").attr("x1",x).attr("y1",y0).attr("x2",x-(l/2)).attr("y2",y+h);
var r = y0 - y;
// $("#circle").attr("cx",x).attr("cy",y0).attr("r",r);
y += 10;
r -= 10;
_x = r*Math.cos(Math.PI/6);
_y = r*Math.sin(Math.PI/6);
$("#polygon2").attr("points",x + "," + y + " " + (x+_x) +"," + (y+r+_y) + " " + (x-_x) +"," + (y+r+_y));
y += 10;
r -= 10;
_x = r*Math.cos(Math.PI/6);
_y = r*Math.sin(Math.PI/6);
$("#polygon3").attr("points",x + "," + y + " " + (x+_x) +"," + (y+r+_y) + " " + (x-_x) +"," + (y+r+_y));
y += 10;
r -= 10;
_x = r*Math.cos(Math.PI/6);
_y = r*Math.sin(Math.PI/6);
$("#polygon4").attr("points",x + "," + y + " " + (x+_x) +"," + (y+r+_y) + " " + (x-_x) +"," + (y+r+_y));
y += 10;
r -= 10;
_x = r*Math.cos(Math.PI/6);
_y = r*Math.sin(Math.PI/6);
$("#polygon5").attr("points",x + "," + y + " " + (x+_x) +"," + (y+r+_y) + " " + (x-_x) +"," + (y+r+_y));
}
setPol();
</script>
</body>
</html>