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

265
Visualizações
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
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