码迷,mamicode.com
首页 > Web开发 > 详细

html5 js canvas中画星星的函数

时间:2016-01-29 11:59:58      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

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);
             }
         }

 

html5 js canvas中画星星的函数

标签:

原文地址:http://www.cnblogs.com/lunawzh/p/5168044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!