Thurs 10/11 Classes

  • Introduction to classes and objects.
  • Defining a class:

Anatomy of a class (page 124):

  • Declare and initialize a class (eg. use it in your code)
  • Writing a class with arguments (p. 132)

Technical exercises:

  • Go over Chapter 8. Still confused? Try these video tutorials from Shiffman on classes.
  • In Learning Processing do exercises: 8.1, 8.2.
  • Also 8.5. For this exercise, download the example of the bouncing_ball_gravity here and create a ball class. Hint: Your class is going to have the same amount of variables as does this example. And the variables that are constantly changing for your ball (like the x and y coordinate for example) are going to be in your constructor.
  • Take your ball class and make an array of 100 bouncing balls. No idea? Take a look at this video tutorial. Really stuck? Check out example 9.9 in Learning Processing.
  • Note the visualizing time project due date has been extended to next Thursday Oct 18th. For next class please make a post here that breaks your planned project the steps that the program will go through as it progresses. Please do the following:

1) Draw several sketches to show how your program changes over time.

2) Break your program into steps and write these out in a list. Under each of these steps write out what will happen in your code to realize this step. Eg. if I wanted to make a sketch of a plant growing over time where there is a branch for each hour, and they get longer as the hour progresses, my steps might be something like:

  • Draw stem of plant
  • Make a branch class
    • Make a class for a branch (class data: start and stop points, color, thickness, functions to turn on or off, grow, display)
    • Grow branch – map branch length to minutes.
    • Check minutes and update branch length
    • Check whether branch is on or off and display or hide branch
  • Make an array of 24 branches, that are either “on” or “off”. At 5 there will be 5 branches that are turned on so they are displayed.
  • Check hour and turn the corresponding number of branches in the array on or off.
  • Draw background with sky etc.

3) Make a start trying to code one or more of these sketches and bring to the next class.