Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
How do I draw a smooth curve in JS , that repeats the outlines of some object on the image (ex. - mountain or waterfall )?

I'm a newbie in JS and I need to draw a curve, to highlight some object on the image. I understand , I need to use quadraticCurveTo,and found the following example :

const points = [{
    x: 1,
    y: 1
  }, {
    x: 20,
    y: 30
  }, {
    x: 30,
    y: 40
  }, {
    x: 40,
    y: 20
  }, {
    x: 50,
    y: 60
  }]
  
  const canvas = document.querySelector('canvas')
  const ctx = canvas.getContext("2d")
  ctx.beginPath();
  ctx.moveTo(points[0].x, points[0].y);
  
  for (const point of points) {
    const xMid = (point.x + point.x) / 2;
    const yMid = (point.y + point.y) / 2;
    const cpX1 = (xMid + point.x) / 2;
    const cpX2 = (xMid + point.x) / 2;
    ctx.quadraticCurveTo(cpX1, point.y, xMid, yMid);
    ctx.quadraticCurveTo(cpX2, point.y, point.x, point.y);
  }
  ctx.stroke();

What I don't understand is how to define the angle of arc between each 2 points. Nor did I get how to place my control points and what function they fulfill in general (from here I got , it's not the points my curve is going through). Any hint will be very appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!