H
H
hatealleverything2021-03-14 10:39:22
JavaScript
hatealleverything, 2021-03-14 10:39:22

What is the best way to animate the rendering of a canvas bezier curve?

Good afternoon. I have this curve.
604dbd82da679872691356.jpeg
I would like to draw it gradually with animation. Is this best done through an array with dots?
Are there any other options?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2021-03-14
@hatealleverything

draw with a dotted line, changing the stroke offset. The length of the stroke is comparable to the length of the entire curve.

  • setLineDash() - Sets a dash pattern with a dash length long enough to cover the full length of the curve with 1 dash.
  • lineDashOffset  - set the offset of this dash along the line. First, minus_stroke_length, so that nothing is drawn. Then slightly increase with each frame: the curve will begin to appear.

A
A person from Kazakhstan, 2021-03-14
@LenovoId

https://codepen.io/ThreePixDroid/pen/QWjdNqQ

D
Developer, 2021-03-14
@samodum

An array is possible, but not required.
You can sequentially calculate all points and draw them with a delay

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question