• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

151
Views
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);
}
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error