Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda