Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda