<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>
添加回答
举报
0/150
提交
取消