Teaching / ProcessingExercises


Processing Exercises

Adapted from

Variables, Expressions and Statements

  1. Take the sentence: All work and no play makes Jack a dull boy. Store each word in a separate variable, then print out the sentence on one line using println.
  2. Add parenthesis to the expression 6 * 1 - 2 to change its value from 4 to -6.
  3. In Processing, write a program that create a variable named bruce. The program should print the value the expression bruce + 4. Alter your program so that the value printed is 10.

Conditionals

  1. Try to evaluate the following numerical expressions in your head, then use Processing to check your results:
    1. 5 % 2
    2. 9 % 5
    3. 15 % 12
    4. 12 % 15
    5. 6 % 6
    6. 0 % 7
    7. 7 % 0
What happened with the last example? Why? If you were able to correctly anticipate the computer’s response in all but the last one, it is time to move on. If not, take time now to make up examples of your own. Explore the modulus operator until you are confident you understand how it works.
  1. p and q are boolean variables. Evaluate each of the following expressions for all four combinations of values for p and q.
    1. !(p || q)
    2. p && q
    3. !(p && q)
    4. !p or !q
    5. !p and !q
Which of these are logically equivalent?
  1. The following Processing program draws a simple house.\\
  size( 320, 240 );
rect( 20, 120, 100, 100 ); // the house
rect( 55, 170, 30, 50 ); // the door
rect( 40, 140, 20, 20 ); // the left window
rect( 80, 140, 20, 20 ); // the right window
line( 20, 120, 70, 60 ); // the left roof
line( 70, 60, 120, 120 ); // the right roof
Modify this code to place five houses on the display in different locations.
Page last modified on September 23, 2009, at 11:58 AM