S
S
Samat2021-05-04 19:50:06
JavaScript
Samat, 2021-05-04 19:50:06

How to make spiral text on canvas?

const wrap = this.spiralText.nativeElement;
          wrap.width = 400;
          wrap.height = 400;
          const ctx: CanvasRenderingContext2D = wrap.getContext('2d');
          ctx.font = String(
            +this.FONT_SETTINGS.fontWeight + ' ' + this.FONT_SETTINGS.fontSize + 'px ' + this.FONT_SETTINGS.font
          );
          const tElem = this.text?.text.split('')!;

          let centerX = ctx.canvas.width / 2,
            centerY = ctx.canvas.height / 2;

          ctx.clearRect(0, 0, 400, 400);

          ctx.moveTo(centerX, centerY);
          ctx.beginPath();
          for (let i = 0; i < 400; i++) {
            let angle = 0.1 * i;
            let x = centerX + 4 * angle * Math.cos(angle);
            let y = centerY + 4 * angle * Math.sin(angle);
            ctx.fillText(tElem[i], x, y, 25);
          }

Is there technology to do this more gracefully?
How to insert letters so that they take the desired angle and how to set this angle with fillText?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-05-05
@Mileon

just gave an example. I think after looking at it you will be able to make the necessary changes to your code.

spiral twisted counterclockwise

spiral twisted clockwise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question