We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I have this code where I put several images (100) and load them, i've managed to load them in my html page. And as expected they all show after each other. How could I make the appear one by one over time. So that every 10 second I get a new image on the same position. All images are the same size. So the centering should not be a problem.
my sketch.js has this for now
let faces = [];
//var canvas;
function preload(){
for (let i = 0; i < 3; i++) {
faces[i] = createImg('images/' + i + '.jpg');
}
}
function setup() {
createCanvas(800, 900);
//canvas = createCanvas(window.innerWidth, window.innerHeight);
// put setup code here
}
function draw() {
image(faces, 0, 0);
// put drawing code here
}
/*
window.onresize = function(){
var w = window.innerWidth;
var h = window.innerHeight;
cansvas.size(w,h);
}
*/
It should be like an automated slideshow.
Answers
let idx = 0;
.const INTER = 10 * 1000;
.setInterval(() => idx = (idx + 1) % faces.length, INTER);
image(faces[idx], 0, 0);
Hi, I've adjusted the code with you addition.
But it still give me the pictures below each other, also it has lost the restraint of the image size. Could you check if there is anything not done right in my part of the code? Because my guess it can only be wrong in what I put together before.
I left all the other stuff out because I just first want to make this to work before I go to the next step.
Note: I'm working on a npm local server as suggested by p5js pages.
@GoToLoop UPDATE!
It does work! But it first shows me the pictures I have below each other, the last picture is the altering one! And that's working nice! Does this have anything to do with the preload function?
my firefox console gives me
https://p5js.org/reference/#/p5/background
https://p5js.org/reference/#/p5/loadImage
https://OpenProcessing.org/sketch/create
Hi I indeed needed to use the
loadImage()
:) and notcreateImg()
/:) orloadImg()
#-o I marked you answer as answered! :) ^:)^ ^:)^ ^:)^ ^:)^I posted the next step in my project with the new code on openprocessing without the faker.js file (it's paid..). The problem is that it doesn't change the whole word, but each letter after each other. The former sketch is in it for people that are interested in the future.
Or should I make a new question for this?
Ru sure randomName is indeed an array? Seems more likely it is a string! :-?
Jep, I put the faker.name.findName() in a array as
I need to look up some more about putting objects in array's. Also no clue what to set the length to because it should be endless...
class
Fake to store those properties as 1 object:https://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
new
over thatclass
, push() the created instance to an array:const fakes = [];
B-)Since
class
Fake got data only but no methods, an ordinary object can replace that easily: :\">