为什么不出星星
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<canvas id="mycanvas"></canvas>
<script>
var canvas=document.getElementById("mycanvas");
canvas.width=400;
canvas.height=400;
var context=canvas.getContext("2d");
context.fillRect(0,0,canvas.width,canvas.height);
for(var i=0;i<100;i++){
r=Math.random()*10+10;
x=Math.random()*c.width;
y=Math.random()*c.height;
rot=Math.random()*360;
drawstar(context,x,y,r,rot);
}
function drawstar(cxt,x,y,r,rot){
cxt.save();
cxt.translate(x,y);
cxt.rotate(rot/180*Math.PI);
starPath(cxt);
cxt.fillStyle="#fb3";
cxt.strokeStyle="#fd5";
cxt.lineWidth=3;
cxt.lineJoin="round";
cxt.fill();
cxt.stroke();
cxt.restore();
}
function starPath(cxt){
cxt.beginPath();
for(var i=0;i<10;i++){
cxt.lineTo(Math.cos((18+(i*72))*Math.PI/180)*20,-Math.sin((18+(i*72))*Math.PI/180)*0.5*20);
cxt.lineTo(Math.cos((54+(i*72))*Math.PI/180)*20,-Math.sin((54+(i*72))*Math.PI/180)*0.5*20);
}
cxt.closePath();
}
</script>
</body>
</html>