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

112
Visualizações
P5.js curveVertex function is closing at a point

I've created a noise function that pairs with a circle function to create a random noise circle thing that looks pretty cool. My problem is the curveVertex function in P5.js works correctly except for the connection of the first and last vertex. My code is:

let start = Array(50).fill(0); // dont change
let amount = 1; // amount of shapes
let gap = 30; // between shapes
let amplify = 50; // 0 -->
let colorSpeed = 1; // 1 - 9
let colorSeparation = 3; // 0 - 80 recomended 0 - 10

function setup() {

  createCanvas(windowWidth, windowHeight);
  
  for(let  i = 0 ; i < start.length; i++){
    start[i] = random(i);
  }
  
}

function draw() {
  
  background(0);
  
  for(let dnc = (amount + 1) * gap; dnc > gap; dnc -= gap){
    drawNoiseCircle(dnc, getNoise(start.length));
  }
    
  start = start.map( c => c + 0.01 );
  
}

function getNoise(amount){
  
  let lengths = [];
  
  for(let i = 1; i < amount + 1; i++){
    
    let n1 = noise(start[i - 1]);
    let noise1 = map(n1, 0, 1, -amplify, amplify);

    lengths.push(abs(-noise1));
    
  }
  
  return lengths;
  
}

function drawNoiseCircle(radius, lengths){
  
  colorMode(HSB);
  fill(((frameCount + radius) * colorSeparation)/-map(colorSpeed, 1, 10, -10, -1) % 360, 100, 50);
  noStroke()

  let x;
  let y;
  
  beginShape();
  
  for(let l = 0; l < lengths.length; l++){
    
    x = Math.cos(radians(l * 360 / lengths.length)) * (radius + lengths[l]) + width/2;
    y = Math.sin(radians(l * 360 / lengths.length)) * (radius + lengths[l]) + height/2;
    
    curveVertex(x, y);
    
  }
  
  endShape(CLOSE);
  
  stroke("black");
  line(width/2, height/2, width, height/2);
  
  line(width/2, height/2 + 9, width, height/2 + 9);

}
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js"></script>

I understand the endShape(CLOSED) closes the shape with a straight line, but I'm not sure any other way to close the shape.

You can see the pointed edge on the right side, directly in the middle of the shape.

!EDIT!

I've added lines to the shape to show the line segment that isn't affected by the curve vertex. Also, I understand it may not be a very significant problem, but if the amount of vertexes shrink, it becomes a much bigger problem (eg. a square or a triangle).

about 4 years ago · Juan Pablo Isaza
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