size (200,200); background(127); noStroke(); // PART 1 int loc = 50; // Note the use of brackets in the if/else construction if (loc == 50) { println("loc is 50!"); } else { println("loc is not 50!"); } /* // PART 2 // Do something more interesting with those variables - create shapes int loc = 50; int diam = 50; if (loc == 50) { println("loc is 50!"); rect(loc, loc, diam, diam); } else { println("loc is not 50!"); ellipse(loc, loc, diam, diam); } // PART 3 // Change the int to a float because randomn produces float data not int float loc = random(100); int diam = 50; // Use a relational operator to determine the value of loc // and moke a decision based on that value. // Relational Operators: // > (greater than) // < (less than) // >= (greater than or equal to) // <= (less than or equal to) // == (equality) // != (inequality) if (loc <= 50) { println("loc is less than or equal to 50!"); rect (loc, loc, diam, diam); } else { println("loc is more than 50!"); ellipse(loc, loc, diam, diam); } // PART 4 float loc = random(100); float diam = random (100); // Use logical operator to test for more than one condition at once // Logical operators // || (logical OR) // && (logical AND) // ! (logical NOT) if (loc <= 50 && diam <= 50) { println("loc is less than or equal to 50 and daim is less than or equal to 50"); rect(loc, loc, diam, diam); } else if (loc <= 50 && diam > 50) { println("loc is less than or equal to 50 and daim is greater than 50"); fill(0); rect(loc, loc, diam, diam); } else if (loc > 50 && diam <= 50) { println("loc is more than 50 and daim is less than or equal to 50"); ellipse(loc, loc, diam, diam); } else if (loc > 50 && diam > 50) { println("loc is more than 50 and daim is greater than 50"); fill(0); ellipse(loc, loc, diam, diam); } // PART 5 float loc = random(100); float diam = random (100); // Use nested conditionals to test values and change results in a more flexible manner // It becomes even more important here to understand the role of the curly bracket // and how it relates to the scope of the commands if (loc <= 50) { println("loc is less than or equal to 50"); if (diam <= 50) { println ("daim is less than or equal to 50"); } else { println ("daim is greater than 50"); fill (0); } rect(loc, loc, diam, diam); } else { println("loc is more than 50"); if (diam <= 50) { println ("daim is less than or equal to 50"); } else { println ("daim is greater than 50"); fill (0); } ellipse(loc, loc, diam, diam); } // PART 6 float loc = random(100); float diam = random (100); // Use an iteration to keep drawing shapes randomly on top of each other until an arbitrary number of shapes has been drawn // Controls a sequence of repetitions. A for() structure has three parts: init, test, and update. // Each part must be separated by a semi-colon ";". The loop continues until the test evaluates to false. // When a for() structure is executed, the following sequence of events occurs: // 1. The init statement is executed // 2. The test is evaluated to be true or false // 3. If the test is true, jump to step 4. If the test is False, jump to step 6 // 4. Execute the statements within the block // 5. Execute the update statement and jump to step 2 // 6. Exit the loop. for(int i=0; i<3; i=i+1) { if (loc <= 50) { println("loc is less than or equal to 50"); if (diam <= 50) { println ("daim is less than or equal to 50"); } else { println ("daim is greater than 50"); fill (0); } rect(loc, loc, diam, diam); } else { println("loc is more than 50"); if (diam <= 50) { println ("daim is less than or equal to 50"); } else { println ("daim is greater than 50"); fill (0); } ellipse(loc, loc, diam, diam); } // you must tell the computer to generate new random numbers at the end of the cycle // or you will simply repeat drawing the same shape over and over loc = random(100); diam = random (100); // in this construction you must als tell the computer to set the fill color to white each time // or you might end up drawing a shap with a small diameter that is black! fill(255); } */