String pageText; PImage nightWatchman; PImage tree1; PImage background; Boolean eyeLids = false; float tLidPos; //top eyelid position float bLidPos; //bottom eyelid position float bookXPos; //book position along shelves float bookYPos; //shelf position float bookHeight = 0; Boolean books = true; float count=0; float[] bookList; void setup() { size(800, 800); background(150, 0, 0); nightWatchman = loadImage("nightWatchman2.png"); background = loadImage("background.png"); tree1 = loadImage("tree1.png"); } void draw() { noStroke(); image(background, 0, 0); //books drawBooks(); //eyes fill(255); ellipse(655, 287, 35, 35); ellipse(703, 287, 35, 35); fill(0); ellipse(655, 287, 15, 15); ellipse(703, 287, 15, 15); //eyeLids fill(230, 198, 177); if (eyeLids == true) { for (int i=0; i<20; i++) { //top eyelids tLidPos = 251+i; rect(638, tLidPos, 35, 20); rect(686, tLidPos, 35, 20); } for (int b=0; b<15; b++) { //bottom eyelids bLidPos = 304-b; stroke(200, 156, 132); rect(638, bLidPos, 35, 15); rect(686, bLidPos, 35, 15); } } //night watchman image(nightWatchman, 0, 0); //text box and text fill(255); rect(50, 600, 700, 150); fill(0); pageText = " hen the library is closed and the night watchman has fallen asleep "; pageText += "in his big armchair, the shelves come to life. Doors and windows appear on "; pageText += "the backs of the books, lights come on, and the sound of voices drifts out "; pageText += "between the pages. Full grown trees spring up and chimneys begin to smoke. "; pageText += "Staircases and ladders join the shelves into great cities, and in the distance "; pageText += "small dogs bark."; textSize(27); text("W", 71, 635); textSize(15); text(pageText, 70, 620, 670, 140); noStroke(); ellipse(mouseX, mouseY, 30, 30); } void mouseClicked() { if (mouseX >= 544 && mouseX <=800 && mouseY >=200 && mouseY<800) { eyeLids = true; count++; redraw(); } } void drawWindow(float x, float y) { fill(255, 232, 71); rect(x, y, 20, 30); stroke(111, 71, 23); line(x, y, x+20, y); line(x, y+30, x+20, y+30); line(x, y, x, y+30); line(x+20, y, x+20, y+30); line(x+10, y, x+10, y+30); line(x, y+15, x+20, y+15); } void drawBooks() { for (int j=0; j<17; j++) { for (int n=0; n<3; n++) { fill(random(100, 255), 101, 100); bookXPos = j*44 +27; bookYPos = n*255 +258; bookHeight = random(190, 221); bookList = new float[17]; bookList[0] = bookHeight; bookList[1] = bookHeight; bookList[2] = bookHeight; bookList[3] = bookHeight; bookList[4] = bookHeight; bookList[5] = bookHeight; bookList[6] = bookHeight; bookList[7] = bookHeight; bookList[8] = bookHeight; bookList[9] = bookHeight; bookList[10] = bookHeight; bookList[11] = bookHeight; bookList[12] = bookHeight; bookList[13] = bookHeight; bookList[14] = bookHeight; bookList[15] = bookHeight; bookList[16] = bookHeight; //tells the program not to draw books between these coordinates if (bookXPos >= 150 && bookXPos <=320 && bookYPos >= 283 && bookYPos <= 514) { books=false; } else { books=true; } //everywhere else, draw books if (books == true) { rect(bookXPos, bookYPos-bookList[j], 40, bookList[j]); } } } noLoop(); }