Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
Make random curvy lines or segments for paths on Canvas

Here is the code that I tried:

var myPath = new Path();
myPath.strokeColor = 'red';
myPath.strokeWidth = 5;
myPath.dashArray = [20, 5];
myPath.add(new Point(1800, 120));

function onFrame(event) {
    if(event.count%10 == 0) {
        var angle = Math.random(0, 1)*Math.PI;
        var all_points = myPath.segments.length;
        var last_point = myPath.segments[all_points - 1];
        myPath.add(new Point(last_point.point.x + 40*Math.cos(angle*(180 / Math.PI)), last_point.point.y + 40*Math.sin(angle*(180 / Math.PI))));
        myPath.smooth({type: 'geometric', factor: 2});
    }
}

I was thinking this would choose a random angle between 0 and Math.PI and then plot the points from the last point. However, it just draws a line at 45 degree going back and forth. I did a console.log() for the angle and it is always something random between 0 and Math.PI.

I want to achieve something similar to this: https://codepen.io/speaud/pen/ExxzrL

Here is what I have so far. My idea was to get a random angle and then gets sin and cosine values for that angle and add them to the last point in the path. This would move the path randomly in a certain direction.

I was hoping that it would create nice curvy non-intersecting paths but the path goes over the same place multiple times also making it smooth with the smooth() function changes its previous course a little.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Math.cos and Math.sin get angle in radians but in your code you convert them to degrees

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda