0

Is there any way to create an arc text using canvas? I followed the answer our here:

How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)

Best thing I got was curve from roof or bottom. I want arc like this:

enter image description here

  • Possible duplicate of [Bridge Text Effect in HTML5 Canvas](https://stackoverflow.com/questions/19460533/bridge-text-effect-in-html5-canvas) – Kaiido Jun 04 '18 at 09:59

1 Answers1

0

Here is the canvas code:

https://codepen.io/creativedev/pen/oybGMQ

function drawTextArc(context, str, centerX, centerY, radius, angle) {
  var len = str.length,
    s;
  context.save();
  context.translate(centerX, centerY);
  context.rotate(-1 * angle / 2);
  context.rotate(-1 * (angle / len) / 2);
  for (var n = 0; n < len; n++) {
    context.rotate(angle / len);
    context.save();
    context.translate(0, -1 * radius);
    s = str[n];
    context.fillText(s, 0, 0);
    context.restore();
  }
  context.restore();
}
var canvas = document.getElementById('myCanvas'),
  context = canvas.getContext('2d'),
  centerX = canvas.width / 2,
  centerY = canvas.height - 30,
  angle = Math.PI * 0.8,
  radius = 150;

context.font = '30pt Calibri';
context.textAlign = 'center';
context.fillStyle = 'green';
context.lineWidth = 4;
drawTextArc(context, 'Vertical Arc', centerX, centerY, radius, angle);

// draw circle underneath text
context.arc(centerX, centerY, radius - 10, 0, 2 * Math.PI, false);
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104