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

91
Visualizações
Vertices in p5.beginShape() not connecting

Essentially I would like for all these disparate lines to be connected in one single path. I am using vector.add() because I would like a cumulative result. Maybe that's the issue? Or perhaps it's how I'm accessing the previous element of the array?

Please take a look at this snippet:

let lifespan = 200;
let genes = [];
let previous;
let prevpos;

function setup(){
  createCanvas(window.innerWidth, window.innerHeight);
  background(255);

  genes[0] = createVector(50,50);

  stroke(0);
  strokeWeight(1);

  beginShape(LINES)
  vertex(genes[0].x, genes[0].y);
  for (let i = 1; i < lifespan; i++) {
    previous = genes[i-1];
    genes[i] = previous.add(createVector(random(-10,10),random(-10,10)));
    // vertex(previous.x, previous.y);
    vertex(genes[i].x, genes[i].y);
  }
  endShape()
}

function draw(){
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div id='sketch'> </div>
    <script language="javascript" type="text/javascript" src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
    <script src="sketch.js"></script>
    <script>
    </script>
  </body>
</html>

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

0

I thought I had tried this already but I just needed to uncomment a line.

beginShape(LINES)
  vertex(genes[0].x, genes[0].y);
  for (let i = 1; i < lifespan; i++) {
    previous = genes[i-1];
    genes[i] = previous.add(createVector(random(-10,10),random(-10,10)));
    vertex(previous.x, previous.y); //<-- uncomment this
    vertex(genes[i].x, genes[i].y);
  }
endShape()
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