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

139
Visualizações
Looping an entire p5js script

I was wondering if it is possible to run the following code on the p5js web editor or within VS code multiple times and change the parameters a, b, A, B, H from an array of predefined values every time it runs and save the PNG image locally. My aim is to let the script run and generate a wide range of plots with these parameters varying. This is a simplified version of my problem so running the loop within the draw loop is not possible. Is there a way to loop the entire script? Many thanks in advance.

//fixed
Sb = 0.3;
Vb = 1;
// noprotect

t = 0;
dt = 0.1 / 2;
t2=0

//want to vary
a = 0.03;
b = 0.04;
A = 20;
B = 20;
H = 0.15;

function setup() {
  createCanvas(1000, 1000, WEBGL);
  colorMode(HSB, 1);

  console.log(width);
  background(H, Sb, Vb);
}

function draw() {
  
  for (i = 0; t < 200 * TAU; i++) {
    W = A * sin(a * t) * B * sin(b * t );
   
  
    strokeWeight(2);
    point(t-width/2,W)

    

    t += dt;
  }
 saveCanvas(join(['Im', 1], '_'), 'png')
  noLoop()
  
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You don't need to loop the whole script, do something like this:

function setup(){

  createCanvas(1000, 1000, WEBGL);
  colorMode(HSB, 1);

  background("white");
  
  iteration(0.03,0.04,20,20,0.15);
  
}

function iteration(a, b, A, B, H){

  const Sb = 0.3;
  const Vb = 1;
  let t = 0;
  const dt = 0.1 / 2;
  const t2 = 0

  background(H, Sb, Vb);

  for (let i = 0; t < 200 * TAU; i++) {
    W = A * sin(a * t) * B * sin(b * t );

    strokeWeight(2);
    point(t-width/2,W)

    t += dt;
  }
  saveCanvas(join(['Im', 1], '_'), 'png');
}
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