Project #1. Presentation / Posting on the website


1. Repetition(LOOP)

A code structure called a ‘for’ loop makes it possible to run a line of code more than once to condense this type of repetition into fewer lines. This makes your programs more modular and easier to change.

  • do-while : rarely used  so we will ignore it
  • while : as with conditional structures, a while  loop employs a boolean test condition: true – the instructions are executed / false,-  continue on to the next line of code
  • for :

• Initialization : a variable is declared and initialized for use within the body of the loop. This variable is most often used inside the loop as a counter.

• Boolean Test : This is exactly the same as the boolean tests found in conditional statements and while  loops. It can be any expression that evaluates to true or false.

• Iteration Expression : an instruction that you want to happen with each loop cycle.

<EXAMPLES>  for(){ } example   /     for(){} : line with ellipse

2. Local vs. Global Variables (AKA “ Variable Scope ” )

  • Global variables,which exist (i.e., are accessible) throughout the entire course of a program’s life

In Processing , global variables are declared at the top of the program, outside of both setup( )  and draw( )  .These variables can be used in any line of code anywhere in the program. This is the easiest way to use a variable since you do not have to remember when you can and cannot use that variable.

  • Local Variables which live temporarily, only for the brief moment when their value is required for an instruction or calculation

Local variables are variables declared within a block of code. So far, we have seen many different examples of blocks of code: setup( ) , draw( ), mousePressed( )  , and keyPressed( ), if statements,and while and for loops….

A local variable declared within a block of code is only available for use inside that specific block of code where it was declared.

4. Class : A NEW DATA TYPE

Objects are also a way to group variables with related functions.

Class has another code block like void setup(), void draw() with :

• The Class Name—The name is specified by “class WhateverNameYouChoose”. We then enclose all of the code for the class inside curly brackets after the name declaration. Class names are traditionally capitalized (to distinguish them from variable names, which traditionally are lowercase).

• Data—The data for a class is a collection of variables.

The constructor is a special function inside of a class that creates the instance of the object itself. It is where you give the instructions on how to set up the object. It is just like Processing’s setup( ) function, only here it is used to create an individual object within the sketch, whenever a new object is created from this class.

•Functionality—We can add functionality to our object by writing methods.

<EXAMPLES>  Class : Object Oriented Programming

CONVERT(?) CAR DRAWING in void draw() into CAR OBJECT with in CLASS

In the context of objects, a variable is called a field and a function is called a method.

3. Image, Live Input, Video import

Using an instance of a PImage object is no different than using a user-defined class.

First, a variable of type PImage, named “img,” is declared.
Second, a new instance of a PImage object is created via the loadImage( ) method. loadImage( ) takes one argument, a String indicating a file name, and loads the that file into memory. loadImage( ) looks for image files stored in your Processing sketch’s data folder.

  • Basic Syntax for PImage

PImage b

b = loadImage(“filename.jpg”);

image(b, 0, 0);

//your source image should be placed in the same directory with the sketch itself (or under data directory)

<EXAMPLES> image with webcam video

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s