码迷,mamicode.com
首页 > 其他好文 > 详细

怎样设置路径的边框(描边)颜色

时间:2019-09-23 14:51:36      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:doctype   path   指定   ora   arc   需要   必须   mamicode   title   

需要使用: ctx.strokeStyle

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <canvas id="canv" width="300" height="300"></canvas>
    <script>
        function draw() {
            var canvas = document.getElementById(canv);
            if (!canvas.getContext) return;
            var ctx = canvas.getContext("2d");
            ctx.beginPath();
            ctx.arc(150, 150, 50, 0, -Math.PI/2, true);
            ctx.strokeStyle = "red";
            ctx.stroke();

            ctx.beginPath();
            ctx.arc(150, 150, 50, -Math.PI/2, -Math.PI, true);
            ctx.strokeStyle = "green";
            ctx.stroke();

            ctx.beginPath();
            ctx.arc(150, 150, 50, -Math.PI, -Math.PI*3/2, true);
            ctx.strokeStyle = "orange";
            ctx.stroke();

            ctx.beginPath();
            ctx.arc(150, 150, 50, -Math.PI*3/2, -Math.PI*2, true);
            ctx.strokeStyle = "blue";
            ctx.stroke();
        }
        draw();
    </script>
</body>

</html>

技术图片

 

注意: 

1. 每次执行 ctx.beginPath() 都相当于是画画时的"落笔"这个动作, 必须要给它指定一个落笔的位置点;

2. ctx.strokeStyle 作用的是当前路径, 也就是最近的一次执行ctx.beginPath()之后绘制的路径; 

怎样设置路径的边框(描边)颜色

标签:doctype   path   指定   ora   arc   需要   必须   mamicode   title   

原文地址:https://www.cnblogs.com/aisowe/p/11572097.html

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