为什么没有星星
<script type="text/javascript">
window.onload = function() {
// 初始化
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
// 画布设置
canvas.width = 800;
canvas.height = 800;
context.fillStyle = "black";
context.fillRect(0,0,canvas.width,canvas.height);
// 绘画星星
// 星星参数
for(var i = 0; i <=200; i++)
{
var r = Math.random()*40+20;
var x = Math.random()*canvas.width;
var y = Math.random()*canvas.height;
var a = Math.random()*360;
draw(context,x,y,r,a);
}
}
function draw(cxt,x,y,r,rot){
cxt.save();
cxt.translate( x , y );
cxt.rotate(rot/180 * Math.PI);
star(cxt);
cxt.fillStyle = "#fb3";
cxt.strokeStyle = "#fd5";
cxt.lineWidth = 3;
cxt.lineJoin = "round";
cxt.fill();
cxt.stroke();
cxt.restore();
}
function star(cxt){
cxt.beginPath();
for(var i = 0; i < 5; i++){
cxt.lineTo(Math.cos((18+i*72)/180*Math.PI*20),
-Math.sin((18+i*72)/180*Math.PI)*20 );
cxt.lineTo(Math.cos((54+i*72)/180*Math.PI)*0.5*20,
-Math.sin((54+i*72-)/180*Math.PI)*0.5*20);
}
cxt.closePath();
}
</script>