N
N
ninja op op2020-03-01 15:23:32
css
ninja op op, 2020-03-01 15:23:32

How to round corners of CANVAS dotted line?

Hello everybody! There is such a code

<canvas id="tutorial" width="359" height="299"></canvas>
<script>
                                var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');

// Так как аргументом функции может быть только радиан,
// а не угол в градусах, то  переводим.
var a = 45 * (Math.PI / 180);
// Длина линии.
var r = 100;


ctx.setLineDash([10, 3]);
ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(Math.sin(a) * r, Math.cos(a) * r);
ctx.lineWidth = 4;
ctx.strokeStyle="#fff";
ctx.stroke();
</script>

Как мне скруглить углы пунктира?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2020-03-01
@kur4chyt

ctx.lineCap = 'round';
it 's all on topic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question