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

89
Views
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 answers
Answer question

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 Report
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!