I like the graphic and text of yours very much!
I changed the approach....
now everything loops all the time, but the books height and color is only defined once randomly in setup() and stored
when you draw the books, we use the stored data
when you click the man, it gets shuffled once
later we use an object Book and store each book there (x,y,height, width, color title) and have an array of those books....
at the moment we have three times the same books on one shelf, we could (and should) also have all different books
- //
- // http://forum.processing.org/topic/make-one-function-not-loop-while-the-rest-do
- 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; // height
- color[] bookColor = new color [17];
- String[] bookTitle = new String [17]; // title
- //
- void setup() {
- size(800, 800);
- background(150, 0, 0);
- nightWatchman = loadImage("nightWatchman2.png");
- background = loadImage("background.png");
- tree1 = loadImage("tree1.png");
- //
- bookList = new float[17];
- //
- 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[j] = bookHeight;
- bookTitle[j] = "";
- bookColor [j] = color (random(100, 255), 101, 100);
- }
- }
- bookTitle[6] = "Homer";
- }
- void draw() {
- background(0);
- 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();
- shuffleSomeBooks();
- }
- }
- //
- void shuffleSomeBooks() { // new
- // shuffle first 6 books.
- for (int j=0; j<7; j++) {
- int partner = int(random(0, 7));
- if (j!=partner)
- swapBooks(j, partner);
- } // for
- }
- //
- void swapBooks( int j, int partner) {
- // swap two books
- color tempCol = bookColor[j];
- float tempHeight = bookList[j];
- String tempTitle = bookTitle[j];
- //
- bookColor[j] = bookColor[partner];
- bookList [j] = bookList [partner];
- bookTitle[j] = bookTitle[partner];
- //
- bookColor[partner] = tempCol;
- bookList [partner] = tempHeight;
- bookTitle[partner] = tempTitle;
- //
- }
- //
- 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( bookColor [j] ); // new
- bookXPos = j*44 +27;
- bookYPos = n*255 +258;
- //
-
- //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]);
- if (bookTitle[j] != "") {
- pushMatrix();
- translate (bookXPos+24, bookYPos-10);
- rotate (-radians(90));
- fill(255);
- text (bookTitle[j], 0, 0);
- popMatrix();
- } // if
- }
- }//for
- }//for
- // noLoop();
- }