Canvas骰子

    var csns=document.getElementById("csns");
    var tcx=csns.getContext("2d");
    csns.style.border="1px red solid";
    tcx.strokeStyle="#1296DB"
    tcx.beginPath();
    tcx.moveTo(95,50);
    tcx.lineTo(170,50);
    tcx.arcTo(190,50,190,70,15);
    tcx.lineTo(190,140);
    tcx.arcTo(190,160,170,160,15);
    tcx.lineTo(100,160);
    tcx.arcTo(80,160,80,140,15);
    tcx.lineTo(80,70);
    tcx.arcTo(80,50,100,50,15);
    tcx.stroke();
    var s=0;
    var createpoint=setInterval(function () {
       tcx.clearRect(90,60,90,90);
       s++;if(s==7)s=0;
       tcx.fillStyle="#1296DB"
       switch(s){
           case 1:
               tcx.beginPath();
               tcx.arc(135,105,20,0,2*Math.PI);
               tcx.fill();
               break;
           case 2:
               tcx.beginPath();
               tcx.arc(112,105,10,0,2*Math.PI);
               tcx.fill();
               tcx.beginPath();
               tcx.arc(158,105,10,0,2*Math.PI);
               tcx.fill();
               break;
           case 3:
               var x=85, y=55;
               for(var i=0;i<s;i++){
                   tcx.beginPath();
                   x+=25;
                   y+=25;
                   tcx.arc(x,y,10,0,2*Math.PI);
                   tcx.fill();
               }
               break;
           case 4:
           case 5:
               var x=110,y=30;
               for(var i=0;i<s;i++){
                   tcx.beginPath();
                   if(i>1){
                       x=160;
                   }
                   if(i==2){  y=30;}
                   y+=50;
                   if(s==5) {
                       if (i == 4) {
                           x -= 25;
                           y -= 75
                       }
                   }
                   tcx.arc(x, y, 10, 0, 2 * Math.PI);
                   tcx.fill();
               }
               break;
           case 6:
               var x=0,y=55;
               for(var i=0;i<s;i++){
                   tcx.beginPath();
                   if(i>2){
                       x=110;
                   }else{
                       x=160
                   }
                   if(i==3){  y=55;}
                   y+=25;
                   tcx.arc(x,y,10,0,2*Math.PI);
                   tcx.fill();
               };
               break;
       }
    },200);

 

转载于:https://www.cnblogs.com/leitong/p/7447787.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值