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

195
Visualizações
having difficulty running p5js generative line art code

I am a beginner and am working on learning generative art and creative coding. this code aims at generating lines randomly and the number of iterations is random as well.

https://editor.p5js.org/rawrro/sketches/j4V6zpnMr

code:

function setup() {
  createCanvas(windowWidth-20, windowHeight-20);
  
    for (let i = random(100); i>0; i--);
   
    {
      
line(random(0,600),random(0,600),random(0,600),random(0,600))
 
    }   
}

function draw() {
  background(GRAY);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First, there is a problem of syntax in the for loop, There must not be a semicolon after for(). Correct syntax:

for (let i = random(100); i>0; i--) {
    line(random(0,600),random(0,600),random(0,600),random(0,600));
}

Second, the setup() function is executed once at the start, the draw() function is executed 60 times per second. Here, you erase the lines by defining a background color in draw(). If you want the lines to be generated each frame, the for loop should be in draw() (but the animation will be too fast!)

Third, but it's not important, the random function doesn't need two arguments: random(600) will generate a random value between 0 and 600.

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