I’m trying to display images (10 or more) randomly when you click on the canvas. At the moment there is only one image displayed, and I don’t know how to proceed for the rest. Should I use img(); or createImg(); ?
let imgs = [];
function preload() {
for (var i = 0; i < 10; i++) {
imgs[i] = loadImage("assets/img_" + i + ".png");
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(245);
imageMode(CENTER);
}
function mouseClicked() {
var index=int(random(9));
image(imgs[index], mouseX, mouseY, 200, 360);
}
function draw() {
}
function keyTyped() {
if (key === 'a') {
clear();
}
}
And it’s very strange because, the code working on the editor, but in present mode the images do not load… The error in the console: “Failed to load resource: the server responded with a status of 404 ()”