Untitled
unknown
plain_text
5 months ago
1.2 kB
0
Indexable
let images = []; let currentImageIndex = 0; function setup() { createCanvas(400, 400); // Create a file input let fileInput = createFileInput(handleFile); fileInput.position(10, 10); let prev = createButton("Previous"); prev.position(10, 40); let next = createButton("Next"); next.position(80, 40); prev.mousePressed(goPrev); next.mousePressed(goNext); } function draw() { background(220); // Display the selected image if (images.length > 0) { let currentImage = images[currentImageIndex]; image(currentImage, 0, 0, width, height); } } function handleFile(file) { // Check if it's an image file if (file.type === 'image') { // Create an image element from the file let img = createImg(file.data, 'selected image'); img.hide(); // Hide the original image element // Add the image to the array images.push(img); // Set the current image index to the last added image currentImageIndex = images.length - 1; } else { console.log('Not a valid image file'); } } function goPrev() { if(currentImageIndex > 0) { currentImageIndex--; } } function goNext() { if(currentImageIndex < images.length - 1) { currentImageIndex++; } }
Editor is loading...
Leave a Comment