html5 js canvas中画星星的函数

function drawStar(cxt, x, y, outerR, innerR, rot) {
             cxt.beginPath();
             for (var i = 0; i < 5; i++) {
                 cxt.lineTo(Math.cos((18+i*72-rot)/180*Math.PI)*outerR+x,
                 -Math.sin((18+i*72-rot)/180*Math.PI)*outerR+y);
                 cxt.lineTo(Math.cos((54 + i * 72 - rot) / 180 * Math.PI) * innerR + x,
                     -Math.sin((54 + i * 72 - rot) / 180 * Math.PI) * innerR + y);
             }
             cxt.closePath();

             cxt.fillStyle = "#fb3";
             cxt.strokeStyle = "#fd5";
             cxt.lineWidth = 3;
             cxt.lineJoin = "rount";

             cxt.fill();
             cxt.stroke();
         }
function draw() {
             for (var i = 0; i < 200; i++) {
                 var r = Math.random() * 10 + 10;
                 var x = Math.random() * cvs.width;
                 var y = Math.random() * cvs.height;
                 var a = Math.random() * 360;
                 drawStar(context, x, y, r, r / 2.0, a);
             }
         }
原文地址:https://www.cnblogs.com/lunawzh/p/5168044.html