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

109
Visualizações
Growing line base on dataset p5js

I want to animate a growing line based on a dataset, I want the line to grow each time the program finds DAE in a Row of the third column.

Here is my p5js code here

let data; 
let font; 
let direction; 
let montant; 
let annee; 

function preload() {
  data=loadTable('data/subvention.csv','csv','header',chargementOK,chargementERROR);
  font = loadFont("data/opensans.ttf");
}

function setup() {
  createCanvas(700, 700);
}

function draw() {
  background(1); 
  
  let nbDAE=0;

  for (let i = 0; i < data.getRowCount(); i++) { 
    
    direction = data.getString(i, "direction"); 
    
    if (direction == "DAE") { 
      nbDAE++; 
      fill(255);
      rect(350, 700- nbDAE*12, 20, 700);
    }
    
  }

}

function chargementOK(mesData){
  print("chargement OK");
  print(mesData);
}
function chargementERROR(){
  print("BUGG");
}

The problem is I think I did everything right but I'm not getting any animation from it, the line just appears and code keeps on going forever.

I need some help to figure out how to properly animate the growing line.

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

0

The draw() loop is executed 60 times per second, and in each loop, you have another loop wich totalizes all the values.

If you want to animate, you need to use a counter and increment it each draw() loop. Initialization of counter and nbDAE should be at the exterior of the draw() loop.

function draw() {
  background(0); 
  direction = data.getString(compteur, "direction"); 
  if (direction == "DAE") { 
      nbDAE++; 
  }
  fill(255);
  rect(350, 700- nbDAE*12, 20, 700);
  
  compteur += 1;
  if (compteur >= data.getRowCount()) {
    noLoop();
  }
}

I had worked on your previous question : here on the p5js web editor

And on your previous question, the problem of csv file : In french, the separator is semicolon (;) and not comma (,). So, in the loadTable() function, the extension should be 'ssv' and not 'csv' (semicolon-separated values)

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