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

108
Visualizações
How can I make objects appear at intervals that decrease over time in p5.js

I'll like to make some elements in an array appear at different times, the time will be decreasing over time (so the elements will appear faster and faster). I had tried with setTimeout and setInterval with no luck, I think it is because I'm looping through the array.

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

0

You cannot achieve that via intervals. Yet, it's possible with recursive timeouts. For example, let's say that the time is decreasing by 2x:

const initialDuration = 10000;

function someAnimation(duration) {
    // Your animation code here...

    setTimeout(() => someAnimation(duration / 2), duration);
}

someAnimation(initialDuration);
about 4 years ago · Juan Pablo Isaza Relatório

0

Here's a simple p5.js example that should hopefully point you in the right direction.

I'm calling the setTimeout function for every object on initialisation. The delay of the timeout is incremented by a value incrementor which decreases each iteration.

let circles = [];
let count = 100;
let incrementor = 500;
let delay = 500;

function setup() {
  createCanvas(400, 400);
  
  for (let i = 0; i < count; i++) {
    let circle = {
      x: random(width),
      y: random(height),
      show: false,
      
    }
    incrementor *= 0.9;
    delay += incrementor;
    setTimeout(() => circle.show = true, delay);
    circles.push(circle);
    
  }
}

function draw() {
  background(220);
  noStroke()
  fill(0, 128, 128);
  for (let circle of circles) {
    if (circle.show) {
      ellipse(circle.x, circle.y, 10, 10);
    }
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

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