Here is my code for a 3d spinning cube and using texture to lay images from an array, json file, to project on to the cube.
The image update currently is at the sketch frame rate and I want to control the update speed but my brain is fried.
- see live sketch here
p5 sketch
let img;
let roomFloor;
let wallImage;
var memeImg;
var memez;
var montage = [];
var montageImg = [];
// var images = [
// 'https://i.imgflip.com/cv1y0.jpg',
// 'https://i.imgflip.com/46rh.jpg',
// 'https://i.imgflip.com/2puag9.jpg'
// ];
let slideShow
var images = [];
function preload() {
font1 = loadFont('itc-avant-garde-gothic-std-bold-589572c7e9955.otf');
roomFloor = loadImage('2.png');
wallImage = loadImage('background.gif');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
let urls = 'https://api.imgflip.com/get_memes';
loadJSON(urls, arrayUrl);
function arrayUrl(meme) {
var imageUrl = meme.data.memes
for (var j = 0; j < imageUrl.length; j++) {
// print(imageUrl[j].url);
}
//----------url array ----------------
for (var k = 0; k < imageUrl.length; k++) {
images[k] = imageUrl[k].url;
print(images[k]);
}
// print(images[0]);
}
img = loadImage(random(images));
}
function draw() {
background(200);
noStroke();
push();
rotateZ(frameCount * 0.01);
rotateX(frameCount * 0.01);
//plane(100,100);
texture(img)
box(150);
pop();
push();
fill(255, 255);
translate(0, 200);
rotateX(HALF_PI);
texture(roomFloor);
plane(2000, 500);
pop();
push();
fill(255, 255);
translate(0, -25, -300);
texture(wallImage);
tint(255, 126);
plane(800, 500);
pop();
if (frameCount % 10) {
img = loadImage(random(images));
}
}
Any help much appreciated
ps also see p5 sketch link