xxxxxxxxxx
84
class Closet {
constructor() {
this.clothesImages = [];
this.currentImageIndex = 0;
this.nextButton = null;
this.backButton = null;
}
// Load the images into the closet
loadImages() {
this.clothesImages.push(loadImage("clothes1 Large.png"));
this.clothesImages.push(loadImage("clothes2 Large.png"));
this.clothesImages.push(loadImage("clothes3 Large.png"));
this.clothesImages.push(loadImage("clothes4 Large.png"));
this.clothesImages.push(loadImage("clothes5 Large.png"));
this.clothesImages.push(loadImage("clothes6 Large.png"));
this.clothesImages.push(loadImage("clothes7 Large.png"));
this.clothesImages.push(loadImage("clothes8 Large.png"));
this.clothesImages.push(loadImage("clothes9 Large.png"));
}
// Set up the buttons and initial configuration
setup() {
// Create buttons
this.nextButton = createButton('→');
this.backButton = createButton('←');
// Position buttons on each door of the closet
this.nextButton.position(355, 180); // Right door button
this.backButton.position(45, 180); // Left door button
// Style buttons (optional)
this.nextButton.size(50, 20);
this.backButton.size(50, 20);
// Add functionality to the buttons
this.nextButton.mousePressed(() => this.showNextImage());
this.backButton.mousePressed(() => this.showPreviousImage());
}
// Display the closet and current image
display() {
// Closet drawing
strokeWeight(3);
// Closet frame
rectMode(RADIUS);
fill(166, 138, 109);
rect(225, height - 250, 125, 150); // Closet body
// Closet doors
rectMode(CORNER);
fill(196, 164, 132);
rect(100, 343, 250, 75);
rect(110, 360, 230, 50); // Door base
// Closet top shelf
fill(192);
strokeWeight(0);
rect(100, 90, 250, 5);
// Closet handle
rectMode(CENTER);
strokeWeight(2);
fill(170, 127, 36);
rect(225, 385, 40, 5); // Handle
// Display the current image in the center of the closet
if (this.clothesImages[this.currentImageIndex]) {
imageMode(CENTER);
image(this.clothesImages[this.currentImageIndex], 225, 200, 150, 200); // Display image in the center
}
}
// Show the next image
showNextImage() {
this.currentImageIndex = (this.currentImageIndex + 1) % this.clothesImages.length;
}
// Show the previous image
showPreviousImage() {
this.currentImageIndex = (this.currentImageIndex - 1 + this.clothesImages.length) % this.clothesImages.length;
}
}