为了账号安全,请及时绑定邮箱和手机立即绑定

我的为什么效果没有星星呢==明明和老师的差不多,到底哪里出错鸟==

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>star</title>
    <style>
    canvas{
        border: solid 1px black; 
        display: block;
    }
    </style>
</head>
<body>
    <canvas id="canvas" width="800" height="800"></canvas>
    <!-- // <script src="../js/star.js"></script> -->
    <script>
    
    window.onload=function(){
        var can=document.getElementById("canvas");
        var ctx=can.getContext("2d");
        var w=can.width;
        var h=can.height;

        ctx.fillStyle="black";
        ctx.fillRect(0, 0, w, h);
        for(var i=0;i<20;i++)
        {

            var r=Math.random()*10+10;
            var x=Math.random()*w;
            var y=Math.random()*h;
            var a=Math.random()*360;

            drawStar(ctx,x,y,r,r/2.0,a);
        }
        // drawStar(ctx,400,400,300,150,30);
    }
    function drawStar(ctx,x,y,R,r,rot){
        ctx.beginPath();
        for(var i=0;i<5;i++)
        {
            ctx.lineTo(Math.cos((18+i*72-rot)/180*Math.PI)*R+x,
                       -Math.sin((18+i*72-rot)/180*Math.PI)*R+x);
            ctx.lineTo(Math.cos((54+i*72-rot)/180*Math.PI)*r+y,
                       -Math.sin((54+i*72-rot)/180*Math.PI)*r+y);
        }
        ctx.closePath();
        ctx.lineWidth=10;
        ctx.fillStyle="#fb3";
        ctx.strokeStyle="#fb5";

        ctx.fill();
        ctx.stroke();
        

    }

    </script>
</body>
</html>


正在回答

3 回答

x y那有问题

1 回复 有任何疑惑可以回复我~
#1

qq_胖漏漏_0 提问者

知道了,蟹蟹~
2016-06-12 回复 有任何疑惑可以回复我~
#2

qq_胖漏漏_0 提问者

蟹蟹~
2016-06-14 回复 有任何疑惑可以回复我~

看着像eclipse,但绝对不是webstorm

qfkciirbanboyvmuglslbhnjgck

0 回复 有任何疑惑可以回复我~


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

这里的x y  位置不对哦

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

我的为什么效果没有星星呢==明明和老师的差不多,到底哪里出错鸟==

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信