Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save...

100
Environment

Transcript of Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save...

Page 1: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Environment

Page 2: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export:1.Run . Compiles the code, opens a display window, and runs the program inside.

2.Stop Terminates a running program, but does not close the display window.

3.New Creates a new sketch.

4.Open Provides a menu with options to open files. Another way of opening files is dragging and the file icon to text editor area or processing icon.

5.Save Saves the current sketch to its current location.

6.Export Exports the current sketch as a Java applet embedded in an HTML file.

Environment-Toolbar Buttons

Page 3: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Your First Piece of Code

void setup(){ size(200,200);}

void draw(){ background(125); float x=mouseX; float y=mouseY; println("Mouse x=" + x + "..... Mouse y=" + y); line (x,y,100,100);}

Page 4: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Environment-Menu Bar

The menus provide the same functionality as the tool bar in addition to actions for file management and opening reference materials.

Page 5: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Under Examples you can find already made codes that you can use as the base of your experiments and achieve the desired result by changing these base codes.

This is what programmers call hacking. Meaning that you do not start a piece of software yourself. You use other’s software and change parts of it, to make it work your way

Environment-Menu Bar-Default Examples

Page 6: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

For example lets go to examples , under basic, under transform, choose arm, and run the code.

Hacking the Default Examples

Page 7: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Let’s say we want the background color white and we want to double the size of the applet.

Hacking the Default Examples

Page 8: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

size(400,400);

Hacking the Default Examples

Page 9: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

background(255);

Hacking the Default Examples

Page 10: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Preexisting Code

Hacking the code

Your code

Hacking the Default Examples

Page 11: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

The export feature packages a sketch to run within a Web browser.

When code is exported from Processing it is converted into Java code and then compiled as a Java applet.

Exporting as a Java Applet on a Webpage

Page 12: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

When a project is exported, a series of files are written to a folder named applet that is created within the sketch folder.

All files from the sketch folder are exported into a single Java Archive (JAR) file with the same name as the sketch.

Exporting as a Java Applet on a Webpage

Page 13: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

index.html is a webpage that contains the java applet and a link to actual code that results in the supported interaction.

If you have a website you can use this feature to place your programs online as a part of your website.

Exporting as a Java Applet on a Webpage

Page 14: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

To see and change the html code on internet explorer go to view>Source

You can edit the html file in a text editor and save it again as html file to see the result of the changes that you have made

Exporting as a Java Applet on a Webpage

Page 15: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In addition to exporting Java applets for the Web, Processing can also export applications for the linux, Macintosh, and Windows platforms.

Exporting as a Application

Page 16: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

When “Export Application” is selected from the File menu, folders will be created for each of the operating systems specified in the Preferences. Each folder contains the application, the source code for the sketch, and all required libraries for a specific platform.

Exporting as a Application

Page 17: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Page setup and print are the same as any conventional text editor program.

Printing the Code

Page 18: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

You can print the code that you have , using print menu option

Printing the Code

Page 19: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

This is where you define the default address for your sketches to be saved

Setting Preferences

Page 20: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Commands on the edit menu control the text editor

Find option is really useful when you have a huge number of code lines and you want to find a specific variable to change it. It is good to memorize the shortcuts for it:Ctrl F for Find and Ctrl G for Find next

Edit Menu-Managing the Code

Page 21: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Present is kind of a cool command too, when you choose to run an application in presentation mode, it covers the whole screen.

They are times that you are checking your code to find out which part is not working and you run it tens of times. It save you a lot of time if you know the shortcut for it.

For presentation it is Ctrl+Shift+R And for Run command it is CTRL+R

Sketch Menu- Running/Presenting the Code

Page 22: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Sketch Menue- Running/Presenting the Code

Presenting is useful when you are finally ready to setup your screen based installation, this way the piece will cover the whole screen

Page 23: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Help menu give you different options and direct you to different web pages on the Processing website

Getting Help-Help Menu

Page 24: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Reference will direct you to a comprehensive index of different processing commands and functions online

You can choose to view the abridged or extended version of the list.

You find all the information that you need for any command or code element in this list.

Getting Help-Online Reference

Page 25: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In the online index you can click on a command to be directed to a page with complete explanation and examples of use of that command

Getting Help-Online Reference

Page 26: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Syntax

Each programming language has specific linguistic details, that defines how the commands should be written. This set of rules is called the syntax of that programming language.

Page 27: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Syntax-Comments

Comments are ignored by the computer but are important for people. They let you write notes to yourself and to others who read your programs.

// Two forward slashes denote a one-line comment.

/* A forward slash followed by an asterisk allows the multi-line Comment to continue until the opposite*/

All letters and symbols that are not comments are translated by the compiler

Page 28: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Syntax-Functions

Functions allow you to execute all types of actions.

A function’s name is usually a lowercase word followed by parentheses.

The comma-separated elements between the parentheses are called parameters, and they affect the way the function works.

Example:

// The size function has two parameters: width and heightsize(200,200);/* Sets the background of the display window in range of 0 (black) to 255 (white) */background(102);

Page 29: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

// The size function has two parameters: width and height

size(200,200);

Function Parameter

Statement Terminator

Comment

Omitting the semicolon at the end of a statement, a very common mistake, will result in an error message, and the program will not run.

Processing-Syntax-Functions

Page 30: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

// ERROR! The B in “background” is capitalized

Background(200);

Processing is Case Sensitive, it differentiates between uppercase and lowercase characters; therefore, writing “Background” when you mean to write “background” creates and error.

Processing-Syntax-Functions

Page 31: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Syntax-Expressions

Expressions are often combinations of operators such as +, *, and / that operate on the values to their left and right. Expressions can also compare two values with operators such as > (greater than) and < (less than). These comparisons are evaluated as true or false. Expression Value

5 5

122.3+3.1 125.4

((3+2)*-10) + 1 -46

6 > 3 true

54 < 50false

Page 32: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Printing Expression Results

The functions print () and println () can be used to display data while a program is running

These functions write text inside the console

You can print the result of expressions or actual sentences to the console using these commands

println("Hello World!");println(5*24-(5/2.34));println("The Result is "+100*10);

Page 33: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In design and implementation of an interactive piece the first step is coming up with an appealing scenario:

What is it that you want your piece to do? What feature of the environment you want your system to be responsive to? What physical property of your environment you want to sense or measure? Which sensor I have to use? Which feature of the environment I want to change based on the sensed data? Which actuator I need to use to change the intended feature or property of environment?How do I want to relate the input and out put of the system?

As a result in the schematic design of the piece you decide which type of data you want to read from environment and which type of data you want to write back to environment or actuators of the environment

Interactivity and Data

Page 34: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Diagram by Kostas Terzidis

Page 35: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Has Video

Page 36: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Has Video

Page 37: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.
Page 38: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.
Page 39: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.
Page 40: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Any interactive object or space is made up of three elements:

First is the physical interface, the stuff that you touch, hear, or see.

Second is the software interface, the commands that you send to the object or space to make it respond.

Third is the electronical interface which are the electronical parts that communicate with the system and each other through sending data and receiving data in form of electrical pulses.

Interactivity and Data

Page 41: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

A microcontroller has no physical interface that humans can interact with directly.

It is just an electronic chip with input and output pins that can send or receive electronical pulses.

Using a micro controller is a three-stage process:

1.You connect sensors to the input pins to convert physical energy like motion, heat and sound into electrical energy

2. You attach motors, speakers, and other devices to the outputs to convert electrical energy into physical action

3.You write a program to determine how the input changes affect the outputs which is basically reading the changes in input data and aplying changes in output data

Interactivity and Data

Page 42: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Every thing that you sense from or send to an environment is in the form of data

Interactivity and Data

Page 43: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

What is data? Data often consists of

measurements of physical attributes.

In software, data is stored as numbers and

characters. Even Sounds, pictures and videos

are stored in computer as a series of numbers

Computers are continually receiving data from

the mouse and keyboard.

Processing-Data-Variables

Page 44: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

What is a Variable? A variable is the container

in which the computer program stores the value

of a data.

The values that are stored in a variable can

change through out the time that the program is

running

A variable has three different attributes:

Type, Name, Value

Processing-Data-Variables

Page 45: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

What is a Data Type? Processing can store

and modify many different kinds of data,

including numbers, letters, words, colors,

images, fonts, and boolean values (true,

false).

The computer stores each in a different way, so

it has to know which type of data is being used

to know how to manage it.

Processing-Data-Variables

Page 46: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Data Types

Page 47: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Boolean variable is often used to make decisions . About which lines of code are

run and which are ignored.

For example, imagine that you write a piece of code that turns on the light in a room of

it detects that it is dark outside and there is not enough light coming from the window:

The pseudo-code would be as follows:

A Boolean variable called “is it night yet?” is initiated

check the value of “is it night yet?” variable

if the value of “is it night yet?” is true , to turn on the light

if the value of “is it night yet?” is false, not to turn on the light

Processing-Data Types

Page 48: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

A variable is a container for storing data.

Variables allow a data element to be reused

many times within a program.

Every variable has two parts, a name and a

value. Every variable has a data type that

defines the category of data it can hold.

A variable must be declared before it is used.

A variable declaration states the data type

and variable name. Once a variable is

declared, you can assign values to it.

Processing-Variable Declaration/Assignment

Page 49: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Declaration

int peopleCount;

Data Type Variable Name

Page 50: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

peopleCount = 127;

Variable Name value

Assignment Operator

Page 51: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

peopleCount = 127;

Variable Name value

Assignment Operator

Page 52: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

peopleCount = peopleCount+1;

Variable Name value

Assignment Operator

Page 53: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Declaration

float temperature;

Data Type Variable Name

Page 54: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

temperature = -32.8;

Variable Name value

Assignment Operator

Page 55: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Declaration

String buildingName;

Data Type Variable Name

Page 56: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

buildingName = “Al&D”;

Variable Name value

Assignment Operator

Page 57: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Declaration

boolean isItNight;

Data Type Variable Name

Page 58: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment

isItNight = true;

Variable Name value

Assignment Operator

Page 59: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Variable Assignment/Decleration

String buildingName = “Al&D”;

Variable Name value

Assignment Operator

Data Type

Page 60: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Multiple Variable Decleration

int days, peopleCount, room;

Variable NameData Type

Variable Name Variable Name

Page 61: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

// This is where you declare and initiate variablesint a = 7; //integer is any whole number : ... -5,-4,-3,-2,-1,0,1,2,3,4,5,...float b = 14.3; // float is any number with decimal part : 1.00, 14.78, -6.5String c = "Nashid"; // String is any alphabetical combination, when declaring use double quoteschar d = 'N'; // char is any character, when declaring use single quotesprintln("a = "+ a); println("b = "+ b); println("c = "+ c); println("d = "+ d); print("a+b = "); println(a+b); print("a-b = "); println(a-b); print("a*b = "); println(a*b); print("a/b = "); println(a/b);

Processing-Variable Assignment/DeclerationPrinting Variable Values to Console

Page 62: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Graphical Elements-Frame Sizesize(height , width);

size(100,100);

size(200,100);

Page 63: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Graphical Elements-Backgroundbackground(GrayValue);background(Red,Green,Blue);

background(100);

background(255,0,0);

The Gray and RGB values can be any number from 0 to 255

Page 64: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Graphical Elements-Background

If you do not know the gray or RGB values of the color that you want you can use the photoshop color picker to find them.

Page 65: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

The Display window is like a canvass that you can create/draw any graphical entity or composition on it.

Like any other drafting environment the first step to create shapes is to specify their coordinates or positions

A position on the screen is comprised of an x -coordinate and a y-coordinate.

In Processing, the origin is the upper-left corner of the display window.

X

Y

Processing-Graphical Elements-Drafting

Page 66: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

point(x,y);

point(40,50);

Processing-Graphical Elements-Shapes

Page 67: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

line(x1,y1,x2,y2);

line(20,30,70,80);

Processing-Graphical Elements-Shapes

Page 68: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

triangle(x1,y1,x2,y2,x3,y3);

triangle(10,10,40,40,25,60);

Processing-Graphical Elements-Shapes

Page 69: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

rect(x,y,w,h);

rect(10,30,60,30);

Processing-Graphical Elements-Shapes

Page 70: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

rectMode(CENTER);// The specified x and y is the center of the shaperect(20,30,30,30);rectMode(CORNER);// The specified x and y is the upper left cornerrect(20,30,30,30);

Processing-Graphical Elements-Shapes

Page 71: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

quad(x1,y1,x2,y2,x3,y3,x4,y4);

quad(38, 31, 86, 20, 69, 63, 30, 76);

Processing-Graphical Elements-Shapes

Page 72: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

ellipse(x,y,w,h);

ellipse(40,30,40,30);

Processing-Graphical Elements-Shapes

Page 73: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

ellipseMode(CENTER);// The specified x and y is the center of the shapeellipse(50,50,40,40);ellipseMode(CORNER);// The specified x and y is the upper left cornerellipse(50,50,40,40);

Processing-Graphical Elements-Shapes

Page 74: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

beginShape();curveVertex(10,10);//Specifies the direction at the first pointcurveVertex(10,30);curveVertex(20,30);curveVertex(45,85);curveVertex(70,20);curveVertex(75,40);curveVertex(10,10);//specifies the direction of the curve at the last pointendShape();

Processing-Graphical Elements-Shapes

Page 75: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to create and place different shapes on the provided canvas:

beginShape();vertex(10,10);vertex(10,30);vertex(20,30);vertex(45,85);vertex(70,20);vertex(75,40);vertex(10,10);endShape();

Processing-Graphical Elements-Shapes

Page 76: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Graphical Elements-ShapesFurther Reading on Shapes and Graphics

Page 77: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to change the visual attributes of the graphics:

noFill();fill(grayValue);

fill(grayValue , transparency);fill(Red , Green , Blue);

fill(Red , Green , Blue , transparency);

The parameters can rage between 0 and 255

Processing-Graphical Elements-Attributes

noFill();rect(10,10,20,20);fill(255);rect(20,20,20,20);fill(200);rect(30,30,20,20);fill(150);rect(40,40,20,20);fill(100);rect(50,50,20,20);fill(50);rect(60,60,20,20);fill(0);rect(70,70,20,20);

Page 78: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to change the visual attributes of the graphics:

noFill();fill(grayValue);

fill(grayValue , transparency);fill(Red , Green , Blue);

fill(Red , Green , Blue , transparency);

The parameters can rage between 0 and 255

Processing-Graphical Elements-Attributes

background(255,0,0);fill(255,255);rect(10,10,20,20);fill(255,200);rect(30,30,20,20);fill(255,150);rect(50,50,20,20);fill(255,100);rect(70,70,20,20);

Page 79: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to change the visual attributes of the graphics:

noFill();fill(grayValue);

fill(grayValue , transparency);fill(Red , Green , Blue);

fill(Red , Green , Blue , transparency);

The parameters can rage between 0 and 255

Processing-Graphical Elements-Attributes

background(255);fill(255,255,0);rect(10,10,20,20);fill(255,0,0);rect(30,30,20,20);fill(255,150,0);rect(50,50,20,20);fill(100,200,50);rect(70,70,20,20);

Page 80: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

COLOR in Computer Graphics

1. Working with color on screen is different from working with color on paper or canvas.2. The most common way to specify color on the computer is with RGB values, where R stands for RED and G

stands For GREEN and B stands for Blue3. An RGB value sets the amount of red, green, and blue light in a single pixel of the screen. If you · look

closely at a computer monitor or television screen, you will see that each pixel is comprised of three separate light elements of the colors red, green, and blue; but because our eyes can see only a limited amount of detail, the three colors mix to create a single color.

4. For example, adding all the colors together on a computer monitor produces white, while adding all the colors together with paint produces black (or a strange brown). A computer monitor mixes colors with light. The screen is a black surface, and colored light is added. This is known as additive color, in contrast to the subtractive color model for inks on paper and canvas. This image presents the difference between these models:

Page 81: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

COLOR in Computer Graphics

1. The intensities of each color element are usually specified with values between 0 and 255 where 0 is the minimum and 255 is the maximum amount of the colored light that can be added to mix

R G B

Red 255 0 0

Magenta 255 0 255

Blue 0 0 255

Cyan 0 255 255

Green 0 255 0

Yellow 255 255 0

White 255 255 255

Black 0 0 0

Page 82: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

RGB Versus HSB1. You can use RGB (RED,GREEN,BLUE) or HSB(Hue,SATURATION,BRIGHTNESS)values of a color.2. Processing uses the RGB color model as its default for working with color.3. The colorMode () function sets the color space for a program:

colorMode(RGB) ; //set the color space to RGBcolorMode(HSB) ; //set the color space to HSB

Page 83: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

HSB in Processing// Change the hue, saturation and brightness constant colorMode(HSB); for (int i = 0; i <100; i++) { stroke(i*2.5, 255, 255);//stroke(hue,Saturation,Brightness) line(i, 0, i, 100); println(i);}

//Change the saturation. hue and brightness constant colorMode(HSB); for (int i = 0; i < 100; i++) { stroke(132, i*2.5, 204); //stroke(hue,Saturation,Brightness) line(i, 0, i, 100); }

//Change the brightness. hue and saturation constant colorMode(HSB); for (int i = 0; i < 100; i++) { stroke(132, 108, i*2.5); //stroke(hue,Saturation,Brightness) line(i, 0, i, 100); }

Page 84: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Shift from one color to another color In RGB // Shift from blue (61,159,204) to green (153,207,61)in RGB mode colorMode(RGB);float r=0;float g=0;float b=0;for (int i = 0; i < 100; i++) { r = 61 + (i*0.92); // You want to go from 61 to 152 in 100 step: 61+i/100*(153-61)=Value at step i g = 159 + (i*0.48);// You want to go from 159 to 207 in 100 step: 159+i/100*(207-159)=Value at step i b = 204 - (i*1.43);// You want to go from 204 to 61 in 100 step: 204+i/100*(61-204)=Value at step i stroke(r, g, b); line(i, 0, i, 100); println(r);println(g);println(b);}

Page 85: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Shift from one color to another color In HSB // Shift from blue to green in HSB mode blue(200,100,100)/green(80,100,100) colorMode(HSB,360,100,100); // the range of hue is 1 to 360, the range of Saturation and Brightness is 1 to 100for (int i = 0; i < 100; i++) { float newHue = 200 - (i*1.2); stroke(newHue, 100, 100); line(i, 0, i, 100);

Page 86: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to change the visual attributes of the graphics:

noStroke();stroke(grayValue);

stroke(grayValue , transparency);stroke(Red , Green , Blue);

stroke(Red , Green , Blue , transparency);

The parameters can rage between 0 and 255

Processing-Graphical Elements-Attributes

Page 87: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In Processing there are different commands to change the visual attributes of the graphics:

strokeWeight(pixels);

The parameters can rage between 0 and 255

Processing-Graphical Elements-Attributes

noFill();strokeWeight(2);stroke(255,0,0);rect(10,10,30,30);strokeWeight(4);stroke(0,255,0);rect(30,30,30,30);strokeWeight(8);stroke(0,0,255);rect(50,50,30,30);

Page 88: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

In computer science every piece of information is saved in memory in the form of a series of 0s and 1s.

The smallest unit of data is called a bit that can store a 1 or a 0 in it.

If we have two bits the possible combinations that can be stored is 2*2 which is four

In the same manner if you have three bits the possible combinations that can be stored is 2*2*2 which is 8

0 0

1 0

0 1

1 1

Why the values range between 0-255?

Page 89: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Byte is an information holder which consists of 8 bites so the number of possible combinations is 2*2*2*2*2*2*2*2 or 2^8 which is 256.

If we start from number 0 , the list of numbers that can be stored in a byte is 0 through 255.

To figure out what is the actual number that is stored in a byte, follow the following formula:

1 0 1 1 0 1 1 0

* 2^7 + * 2^6+ *2^5+ *2^4+ *2^3+ *2^2+ *2^1+ *2^0

1*128+0*64+1*32+1*16+0*8+1*4+1*2+0*1

Why the values range between 0-255?

Page 90: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

1 1 1 1 1 1 1 1

•2^7 + * 2^6+ *2^5+ *2^4+ *2^3+ *2^2+ *2^1+ *2^0

= 1*128+1*64+1*32+1*16+1*8+1*4+1*2+1*1= 255 // White

Why the values range between 0-255?

Page 91: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

0 0 0 0 0 0 0 0

•2^7 + * 2^6+ *2^5+ *2^4+ *2^3+ *2^2+ *2^1+ *2^0

= 0*128+0*64+0*32+0*16+0*8+0*4+0*2+0*1= 0 // Black

Why the values range between 0-255?

Page 92: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Graphical Elements-AttributesFurther Reading on Shape Attributes

Page 93: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Parametric Design

Function(parameter01,parameter02,…);

rect(x,y,w,h);

Has Video

Page 94: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

void setup(){ size(300,300); background(255);}void draw(){ background(255); int rectW=mouseX-10; int rectH=mouseY-10; rect(10,10,rectW,rectH);}

Processing-Parametric Design

Page 95: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Processing-Parametric Design

Page 96: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Any code in processing is executed line by line from top to bottom. Thus the program flow or the sequence in which the lines of code are executed is linear and from top to bottom.

ellipse(30,30,50,50);rect(25,25,50,50);

rect(25,25,50,50);ellipse(30,30,50,50);

Processing-Program Flow

Page 97: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

There are ways to manipulate the sequence of the program flow. One of them is specifying which part of code is run once and which part is run repeatedly.

void setup(){ //this is the block of code that is run once}

void draw(){ //this is the part of code that is run repeatedly while the applet is running}

Processing-Program Flow-setup(),draw()

Page 98: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

There are ways to manipulate the sequence of the program flow. One of them is specifying which part of code is run once and which part is run repeatedly.

void setup(){ size(200,200); background(255);}

void draw(){ // background(255); line(100,100,mouseX,mouseY);}

*** Adding a background function to the draw causes the screen to redraw and erases the trace of the movement of the graphics on the screen

Processing-Program Flow-setup(),draw()

Page 99: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

There are ways to manipulate the sequence of the program flow. One of them is specifying which part of code is run once and which part is run repeatedly.

void setup(){ size(200,200); background(255);}

void draw(){ background(255); rect(mouseX,mouseY,30,30);}

Processing-Program Flow-setup(),draw()

Page 100: Environment. The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: 1.Run. Compiles the code, opens a display.

Another way to manipulate the program flow is using conditional statements. In conditional statements you specify that if a certain condition is met then a certain part of code is executed and otherwise the compiler skips that part of the code.

if ( Logical Expression){

// this is where you put the code that you want to execute if the first condition is met}

else if ( Logical Expression){

// this is where you put the code that you want to execute if the second condition is met

}else{

// this is where you put the code that you want to execute if the second condition is met

}

Program Flow-Conditional Statements