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

canvas七巧板案例源码

<canvas id="mycanvas"></canvas>
        <script type="text/javascript">
                 
                 (function(id){
                     
                      var tangram=[
                      
                                {p:[{x:520,y:40},{x:520,y:170},{x:595,y:110}],color:"#FDAD05"},
                                {p:[{x:595,y:110},{x:670,y:46},{x:670,y:170}],color:"#FC7861"},
                                {p:[{x:670,y:170},{x:595,y:110},{x:520,y:170},{x:595,y:246}],color:"#F2DE0C"},
                                {p:[{x:595,y:246},{x:432,y:390},{x:602,y:555}],color:"#CA9964"},
                                {p:[{x:595,y:246},{x:712,y:350},{x:600,y:465}],color:"#6CA4A7"},
                                {p:[{x:432,y:390},{x:430,y:620},{x:670,y:620}],color:"#F54C42"},
                                {p:[{x:175,y:528},{x:341,y:535},{x:430,y:620},{x:250,y:610}],color:"#9ECF00"}
                                
                                ]
                      
                          var canvas=document.getElementById(id);
                            
                            canvas.width=1090;
                            
                            canvas.height=880;
                
                        var context=canvas.getContext('2d');                         
                             
                            for(var i=0;i<tangram.length;i++)
                            {
                                 
                                context.beginPath();
                                
                                context.moveTo(tangram[i].p[0].x,tangram[i].p[0].y);
                                 
                                for(var j=1;j<tangram[i].p.length;j++){
                                    
                                    context.lineTo(tangram[i].p[j].x,tangram[i].p[j].y);
                                }

                                context.closePath();

                                context.fillStyle=tangram[i].color;
                                
                                context.strokeStyle=tangram[i].color;
                                
                                context.fill();
                                
                                context.stroke();
                        }
                      
                  })('mycanvas')

        </script>

看到很多同学要源码  自己写的一个 七巧板  希望大家做参考  多动手练习

正在回答

2 回答

学习了

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

学习了 

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

举报

0/150
提交
取消
炫丽的倒计时效果Canvas绘图与动画基础
  • 参与学习       96725    人
  • 解答问题       999    个

学习HTML5中最激动人心的技术Canvas,彻底释放自己的创造力

进入课程

canvas七巧板案例源码

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