猿问

试了很久,没有找到问题在哪,请大神指教。。。

<canvas id="canvas"></canvas>

<script type="text/javascript" language="javascript">

window.onload=function () {

var canvas=document.getElementById('canvas');

canvas.width=800;

canvas.height=800;

var context=canvas.getContext("2d");

context.lineWidth=5;

context.fillStyle="#000";

context.fillRect(0,0,canvas.width,canvas.height);

for (var i = 0; i< 200; i++){

var ra = Math.random()*10+10;

var a = Math.random() * canvas.width;

var b = Math.random() * canvas.height;

var ro = Math.random() * 360;

drawStar(context,a,b,ra,ra/2.0,ro);

}

drawStar(context,200,200,30,60,90);

}

function drawStar(cxt,x,y,r,R,rot) {

cxt.beginPath();

for (var i = 0; i < 5; i++) {

cxt.lineTo(Math.cos((18+i*72-rot)/180*Math.PI)*R+x,-Math.sin((18+i*72-rot)/180*Math.PI)*R+x);

cxt.lineTo(Math.cos((54+i*72-rot)/180*Math.PI)*r+y,-Math.sin((54+i*72-rot)/180*Math.PI)*r+y);

}

cxt.fillStyle="#ff0";

cxt.fill();

cxt.closePath();

}

</script>


smilevs
浏览 1067回答 1
1回答

smilevs

已经找到问题所在 谢谢
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答