generateTextures()
generateTextures() uses createGraphics() to build five textures procedurally—this is much faster and more flexible than loading image files. Each texture is drawn into an off-screen buffer and stored in a global object so room geometry can apply them via the texture() function in WEBGL mode.
🔬 This creates a checkerboard floor—what happens if you swap the rect coordinates to g.rect(100,0,100,100); g.rect(0,100,100,100)? Try it and see how the checker pattern flips.
// 2. Floor Texture (Carpet)
g = createGraphics(200, 200);
g.background(30, 30, 40);
g.noStroke();
g.fill(40, 40, 50);
g.rect(0,0,100,100); g.rect(100,100,100,100); // Checkers
textures.floor = g;
function generateTextures() {
// 1. Wall Texture (Wallpaper)
let g = createGraphics(200, 200);
g.background(50, 40, 30); // Dark brown
g.stroke(70, 60, 50);
g.strokeWeight(2);
for(let i=0; i<200; i+=20) g.line(i, 0, i, 200); // Stripes
textures.wall = g;
// 2. Floor Texture (Carpet)
g = createGraphics(200, 200);
g.background(30, 30, 40);
g.noStroke();
g.fill(40, 40, 50);
g.rect(0,0,100,100); g.rect(100,100,100,100); // Checkers
textures.floor = g;
// 3. Door Texture
g = createGraphics(100, 200);
g.background(60, 40, 20);
g.fill(40, 20, 10);
g.rect(10, 10, 80, 180); // Panel
g.fill(200);
g.circle(85, 100, 10); // Handle
textures.door = g;
// 4. Wardrobe Texture
g = createGraphics(200, 400);
g.background(50, 30, 10);
g.fill(30, 10, 0);
g.rect(10, 10, 180, 380); // Inset
g.fill(100);
g.rect(20, 50, 160, 10); // Slats
g.rect(20, 80, 160, 10);
g.rect(20, 110, 160, 10);
textures.closet = g;
// 5. Rush Face (Procedural Horror)
g = createGraphics(256, 256);
g.clear(); // Transparent background
g.fill(30); g.noStroke(); g.circle(128, 128, 200); // Head
g.fill(0);
g.ellipse(80, 100, 50, 70); // Eye L
g.ellipse(176, 100, 50, 70); // Eye R
g.fill(255); // Teeth
g.rect(60, 160, 136, 40);
textures.rush = g;
}
Line-by-line explanation (8 lines)
🔧 Subcomponents:
for(let i=0; i<200; i+=20) g.line(i, 0, i, 200);
Draws evenly-spaced vertical lines to create a striped wallpaper effect
g.rect(0,0,100,100); g.rect(100,100,100,100);
Draws alternating squares to create a checkerboard carpet pattern
g.circle(128, 128, 200); g.fill(0); g.ellipse(80, 100, 50, 70); g.ellipse(176, 100, 50, 70);
Procedurally draws a horrific face with a dark head and large void-black eyes
let g = createGraphics(200, 200);- Creates an off-screen graphics buffer 200×200 pixels to draw textures into without affecting the main canvas
g.background(50, 40, 30);- Fills the graphics buffer with a dark brown color that will be the wallpaper base
for(let i=0; i<200; i+=20) g.line(i, 0, i, 200);- Loops 10 times, drawing vertical lines spaced 20 pixels apart to create vertical stripes on the wall
textures.wall = g;- Stores this completed texture in the global textures object so it can be applied to wall geometry later
g.rect(0,0,100,100); g.rect(100,100,100,100);- Draws two light-colored squares diagonally opposite to create a classic checkerboard floor pattern
g.clear();- Makes the Rush face texture transparent so only the drawn features (head, eyes, teeth) are visible
g.circle(128, 128, 200);- Draws a large dark circle at the center to form the head of the Rush entity
g.ellipse(80, 100, 50, 70);- Draws a tall dark ellipse on the left side to represent the left eye—tall proportions make it unsettling