canvas画流程图

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
</head>
<body>
    <div>
        <canvas id="myCanvas" height="600px" width="1200px"></canvas>
    </div>
</body>
</html>
<script>
    var mycanvas = document.getElementById('myCanvas');
           var ctx = mycanvas.getContext("2d");
           //流程块
            function Can(ctx,Bolds,BorderColor,DistanceX,DistanceY,Widths,Hights,Bcolor,FontColor,FontS,Texts,textX,textY){
                     //边框背景
                ctx.beginPath();
                ctx.lineWidth=Bolds;
                ctx.strokeStyle=BorderColor;//边框颜色
                ctx.rect(DistanceX,DistanceY,Widths,Hights);
                ctx.fillStyle=Bcolor;//背景颜色
                ctx.fill();
                ctx.fillStyle=FontColor;//字体颜色
                ctx.font = FontS;
                ctx.fillText(Texts, textX, textY);
                ctx.stroke();
                ctx.closePath();
           };
           //字体
           function Fon(FontS,Texts,textX,textY,color){
                ctx.beginPath();
                ctx.font = FontS;
                ctx.fillStyle=color;
                ctx.fillText(Texts, textX, textY);
                ctx.stroke();
                ctx.closePath();
           }
           //箭头
            function drawArrow(ctx,fromX,fromY,toX,toY,theta,headlen,width,color) {
           theta = typeof(theta) != 'undefined' ? theta : 30;
           headlen = typeof(theta) != 'undefined' ? headlen : 10;
           width = typeof(width) != 'undefined' ? width : 1;
           color = typeof(color) != 'color' ? color : '#000'; // 计算各角度和对应的P2,P3坐标
            var angle = Math.atan2(fromY - toY, fromX - toX) * 180 / Math.PI,
                angle1 = (angle + theta) * Math.PI / 180,
                angle2 = (angle - theta) * Math.PI / 180,
                topX = headlen * Math.cos(angle1),
                topY = headlen * Math.sin(angle1),
                botX = headlen * Math.cos(angle2),
                botY = headlen * Math.sin(angle2);
                ctx.save();
                ctx.beginPath();
                var arrowX = fromX - topX;
                var arrowY = fromY - topY;
                ctx.moveTo(arrowX, arrowY);
                ctx.moveTo(fromX, fromY);
                ctx.lineTo(toX, toY);
                arrowX = toX + topX;
                arrowY = toY + topY;
                ctx.moveTo(arrowX, arrowY);
                ctx.lineTo(toX, toY);
                arrowX = toX + botX;
                arrowY = toY + botY;
                ctx.lineTo(arrowX, arrowY);
                ctx.strokeStyle = color;
                ctx.lineWidth = width;
                ctx.stroke();
                ctx.restore();
            };
                Can(ctx,1,"#ccc",10,10,120,50,"#000","#fff","12pt Arial","流程1",40,40);
                Can(ctx,1,"#ccc",280,10,120,50,"#000","#fff","12pt Arial","流程2",316,40);
                Can(ctx,1,"#ccc",550,10,120,50,"#000","#fff","12pt Arial","流程3",570,40);
                Can(ctx,1,"#ccc",820,10,120,50,"#000","#fff","12pt Arial","流程4",855,40);
                Can(ctx,1,"#ccc",1090,10,120,50,"#000","#fff","12pt Arial","流程5",1104,40);
                Can(ctx,1,"#ccc",1090,200,120,50,"#000","#fff","12pt Arial","流程6",1104,232);
                Can(ctx,1,"#ccc",1090,380,120,50,"#ccc","#fff","12pt Arial","流程7",1104,410);
                Can(ctx,1,"#ccc",820,380,120,50,"#ccc","#fff","12pt Arial","流程8",840,410);
                Can(ctx,1,"#ccc",550,380,120,50,"#ccc","#fff","12pt Arial","流程9",570,410);
                Can(ctx,1,"#ccc",280,380,120,50,"#ccc","#fff","12pt Arial","流程10",316,410);
                Can(ctx,1,"#ccc",10,380,120,50,"#ccc","#fff","12pt Arial","流程11",40,410);
                Can(ctx,1,"#ccc",550,200,120,50,"#ccc","#fff","12pt Arial","流程12",586,232);

                //canvas环境,线X轴起点,线Y轴起点,旋转角度x,y,尖角,尖角,颜色
              drawArrow(ctx,130,30,170,30,0,0,1,'green');
              drawArrow(ctx,130,42,170,42,0,0,1,'blue');
              drawArrow(ctx,240,30,280,30,30,10,1,'green');
              drawArrow(ctx,240,42,280,42,30,10,1,'blue');
              //字
              Fon("12pt Arial","李大钊",180,30,"green");
              Fon("12pt Arial","陈独秀",180,60,'red');
</script>

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值