How to draw continuous lines? - perfect-freehand HTML

First of all, very awesome library! Thank you for creating this.

So this isn't really an issue but just want to ask if there's an easy way to do this.

I've tried the React example and it works perfectly!

import * as React from "react"
import getStroke from "perfect-freehand"
import { getSvgPathFromStroke } from "./utils"

export default function Example() {
  const [points, setPoints] = React.useState()

  function handlePointerDown(e) {
    e.preventDefault()
    setPoints([[e.pageX, e.pageY, e.pressure]])
  }

  function handlePointerMove(e) {
    if (e.buttons === 1) {
      e.preventDefault()
      setPoints([...points, [e.pageX, e.pageY, e.pressure]])
    }
  }

  return (
    <svg
      onPointerDown={handlePointerDown}
      onPointerMove={handlePointerMove}
      style={{ touchAction: "none" }}
    >
      {points && (
        <path
          d={getSvgPathFromStroke(
            getStroke(points)
          )}
        />
      )}
    </svg>
  )
}

But this one clears the previous line because there is only one path right? I hope there's an easy example of making it continuous, like in your demo. Thank you!

Asked Mar 15 '23 10:03
avatar mirabledictu
mirabledictu

9 Answer:

What I did for now which is working, I guess

import * as React from "react"
import getStroke from "perfect-freehand"
import { getSvgPathFromStroke } from "./utils"

export default function Example() {
  const [points, setPoints] = React.useState()
  const [paths, setPaths] = React.useState()

  function handlePointerDown(e) {
    e.preventDefault()
    setPoints([[e.pageX, e.pageY, e.pressure]])
  }

  function handlePointerMove(e) {
    if (e.buttons === 1) {
      e.preventDefault()
      setPoints([...points, [e.pageX, e.pageY, e.pressure]])
    }
  }

  function handlePointerUp(e) {
    e.preventDefault()
    setPaths(points)
  }

  return (
    <svg
      onPointerDown={handlePointerDown}
      onPointerMove={handlePointerMove}
      onPointerUp={handlePointerUp}
      style={{ touchAction: "none" }}
    >
      {points && (
        <path
          d={getSvgPathFromStroke(
            getStroke(points)
          )}
        />
      )}
      {paths.map((p,index) => <path
            key={index}
            d={p}/>
       )}
    </svg>
  )
}
1
Answered Jun 21 '21 at 02:07
avatar  of mirabledictu
mirabledictu

Besides the script you can have multiple options besides having an HTML tag for getting some body part bold with it‘s font properties to run effectively for website essay writer IE. Y may run with some limitation working with HTML but you would have plenty pf variations and options how you do this.

1
Answered Jul 07 '22 at 07:07
avatar  of Albert Silva
Albert Silva

We have a lot of fun with the different internet games that are available to us. In the typical course of events, I break every hour to engage in a game of bubble shooter

1
Answered Dec 16 '22 at 06:12
avatar  of Masker Yulia
Masker Yulia

I have learned a lot through this post. Now I can easily do some development amendments to the computation assignment help website without hiring any developer. At the start, I was unable to understand this code. But after going through it deeply I can understand it perfectly.

1
Answered Dec 29 '22 at 12:12
avatar  of Alex Hales
Alex Hales

perfect lines can only be drawn with HTML. we have an expert team of developers who work hard to provide the best customer experience for all. they are currently working for pelle pelle. you can ask anything from them. Thanks

1
Answered Jan 02 '23 at 07:01
avatar  of John Gram
John Gram

The classic Fake SB Dunk Low is already a staple of many sneakerheads. With this colourway on its way, Nike pretty much sticks to its reputation of never-letting-down.

1
Answered Feb 01 '23 at 07:02
avatar  of Yzy Sneakers
Yzy Sneakers

Creating continuous lines through HTML code is not difficult. I am developer and creating child nursing dissertation topics by HTML code. You should know the basics of HTML and download notepad and start writing code.

1
Answered Feb 07 '23 at 05:02
avatar  of Michael Wade
Michael Wade

perfect lines can only be drawn with HTML. we have a team of experienced developers working hard to provide the best customer experience for everyone. they are currently working to describe factors to consider for effective communication. you can ask them anything.

1
Answered Feb 09 '23 at 10:02
avatar  of Ava emily
Ava emily

It is really wonderful and amazing. Now students can easily avail of the best services of Management Assignment Help in the UK and other regions of the world. It is a really good opportunity for students and professionals. Feel free to contact me!

1
Answered Mar 15 '23 at 10:03
avatar  of Kate Berry
Kate Berry