Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
p5.js loadImage and image to set a background image

SOLVED I was missing script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"> in index.html

I am using JavaScript and the p5.js library in VSC and trying to get an image to load to use as a background. Previously I had the script.js and background.png files in separate folders under the same parent directory, but I changed them temporarily to see if the file paths were the problem. The code in script.js stands as following:

let BG;

function preload() {
    BG = loadImage('background.png');
}

function setup() {
    createCanvas(200,200);
    image(BG,0,0,100,100);
}

And as mentioned before, the files are all in the same directory. File structure

I would like to get the image saved as background.png to display on the canvas because currently it does not. I have used loadImage() and image() in exactly this fashion before in preload() and setup(), though this time it is not working. Help is appreciated, thank you.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!