Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Introduction to Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
A Quick Introduction to Processing
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 10, 2009.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
IAT 800 Foundations of Computational Art and Design Lecture 2.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
ICM Week 2. Structure - statements and blocks of code Any single statement ends with semicolon ; When we want to bunch a few statements together we use.
Lecture 3 IAT 800. Sept 15, Fall 2006IAT 8002 Suggestions on learning to program  Spend a lot of time fiddling around with code –Programming is something.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
CSM-Java Programming-I Spring,2005 Control Flow Lesson - 3.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CPS120: Introduction to Computer Science Decision Making in Programs.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Review of ArT3 Programming Course David Meredith Aalborg University
Flow of Control Part 1: Selection
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Applications Development
CIS 3.5 Lecture 2.2 More programming with "Processing"
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
Lesson Two: Everything You Need to Know
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Often being different. Control flow By default Java (and therefore Processing) executes lines of a program one after the other –Doesn’t matter what happened.
LCC 6310 Computation as an Expressive Medium Lecture 2.
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
By Mr. Muhammad Pervez Akhtar
CPS120: Introduction to Computer Science Decision Making in Programs.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Review Expressions and operators Iteration – while-loop – for-loop.
CPS120: Introduction to Computer Science Decision Making in Programs.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
What is Computing? What can be Programmed? Creative Computing Processing Downloading Processing Dropbox Primitive Shapes – point – line – triangle – quad.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
Information and Computer Sciences University of Hawaii, Manoa
Selections Java.
Introduction to C++ Programming
For Net Art Lecture 2 J Parker
More programming with "Processing"
Pages:51-59 Section: Control1 : decisions
Relational, Logical, and Equality Operators
LCC 6310 Computation as an Expressive Medium
Pages:51-59 Section: Control1 : decisions
IAT 800 Foundations of Computational Art and Design
LCC 6310 Computation as an Expressive Medium
Presentation transcript:

Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom shapes Hue-Saturation-Brightness vs. Red-Green-Blue color Example Sketches OpenProcessing website

Odds and Ends Dropbox installation is a two-step process – Sign up for an account with dropbox – Install the dropbox application on your computer After you have installed dropbox – Invitation to join a shared folder named with your user name – This is where all the submissions go! Processing programs carry the extension.pde Processing programs must be in a folder with the same name – myProgram.pde must be inside a folder called myProgram

Syntax Function call – line( 10, 10, 50, 80 ); – Name – The commas – The parens () – The semicolon Code block – The curly braces {} Comments – // – /* and */

Images loadImage(filename); – Loads an image from a file in the data folder in sketch folder. – Must be assigned to a variable of type PImage. image(img, X, Y, [X2, Y2]); – Draws the image img on the canvas at X, Y – Optionally fits image into box X,Y and X2,Y2 imageMode(CORNER); – X2 and Y2 define width and height. imageMode(CORNERS); – X2 and Y2 define opposite corner.

Image Example PImage img; void setup() { size(500, 400); img = loadImage("natura-morta.jpg"); image(img, 50, 40); } imageExample imageExample.pde data natura-morta.jpg

A name to which data can be assigned A variable name is declared as a specific data type Names must begin with a letter, “_” or “$” and can container letters, digits, “_” and “$” boolean bReady = true; int i; int j = 12; float fSize = 10.0; color _red = color(255,0,0); String name123 = “Fred”; PImage img; Variables

Variable Uses Use a value throughout your program, – but allow it to be changed As temporary storage for a intermediate computed result To parameterize – instead of hardcoding coordinates Special variables (preset variables) – width, height – screen.width, screen.height – mouseX, mouseY – pmouseX, pmouseY

Primitive Data Types TypeRangeDefaultBytes boolean{ true, false }false? byte{ }01 int{ -2,147,483, ,147,483,647 } long{ -9,223,372,036,854,775, ,223,372,036,854,775,807 } float{ E E+38 } doublemuch larger/smaller0.08 color{ # #FFFFFFFF }black4 chara single character 'a', 'b', …'\u0000' 2

Other "things" … TypeRangeDefaultBytes Stringa series of chars in quotes “abc”null? PImagean imagenull? PFonta font for rendering textnull? … String message = "Hello World!";

Data Type Conversion Variables of some types can be converted to other types. Type conversion function names are the types to which data will be converted // binary(…), boolean(…), byte(…), // char(…), float(…), str(…) float f = 10.0; int i; //i = f;// Throws a runtime error i = int(f); println( char(65) );// Prints the character 'A'

Mixing types and Integer Division 3*1.5 – value? – type? 3/2 2/3 x/y

Programmatic branching … if ( boolean_expression ) { statements; } // What does this do? void draw() { if ( mouseX > 50 && mouseY > 50 ) { ellipse( mouseX, mouseY, 10, 10 ); } Conditionals: if-statement

Relational Expressions <less than >is greater than <=is less than or equal to >=is greater than or equal to ==is equivalent !=is not equivalent

Relational Expressions: Examples 1.if ( true ) { … } 2.if ( 10 > 10 ) { … } 3.if ( 10 >= 10 ) { … } 4.if ( 'a' == 'a' ) { … } 5.if ( 'a' != 'a' ) { … } 6.if ( "Bryn Mawr" != "bryn mawr" ) { … }

Logical Expressions &&logical conjunction (and) both expressions must be true for conjunction to be true ||logical disjunction (or) either expression must be true for disjunction to be true !logical negation (not) true  false, false  true

Logical Expression Examples 1.if ( (2 > 1) && (3 > 4) ) { … } 2.if ( ("blah" == "blah") && (1 + 2 == 3) ) { … } 3.if ( !false ) { … } 4.if ( !(1 < -1) ) { … } 5.if ( !(10 < 20) || false ) { … } 6.if ( !(10 > 20) && (10 < 20) ) { … } 7.if ( (true || false) && true ) { … } 8.if ( (true && false) || true ) ) { … } 9.…

Conditionals: if-else-statement if ( boolean_expression ) { statements executed when boolean_expression is true; } else { statements executed when boolean_expression is false; } // What does this do? void draw() { if ( mouseY < 50 ) { println("the sky"); } else { println("the ground"); }

Conditionals: if-else-if-statement if ( boolean_expression_1 ) { statements; } else if ( boolean_expression_2 ) { statements; } else if ( boolean_expression_3 ) { statements; } else { statements; }

void setup() { size(500,500); smooth(); ellipseMode(CENTER); } void draw() { if (mouseX < 250) { stroke(255, 0, 0); if (mouseY < 250) { fill(0, 255, 0); } else { fill(0, 0, 255); } } else { stroke(0, 0, 255); if (mouseY < 250) { fill(255, 0, 0); } else { fill(255); } ellipse(mouseX, mouseY, 50, 30); } What will this do?

void setup() { size( 500, 500 ); smooth(); } void draw() { if ( mouseX > 100 ) { background( 255, 0, 0 ); } else if ( mouseX > 200 ) { background( 0, 0, 255 ); } What does this do?

void setup() { size( 500, 500 ); smooth(); } void draw() { if ( mouseX > 200 ) { background( 255, 0, 0 ); } if ( mouseX > 100 ) { background( 0, 0, 255 ); } What does this do?

Equations of Motion (Simplified) r = displacement (position) t = time v = velocity a = acceleration Constant acceleration (a) r i+1 = r i + v i  t v i+1 = v i + a  t Assume small time intervals – i.e.  t = 1

Conditionals: switch-statement switch( expression ) { case label1: // label1 equals expression statements; break; case label2: // label2 equals expression statements; break; default: // Nothing matches statements; } Works like a if-else statement. Convenient for large numbers of value tests.

void setup() { size(500, 500); smooth(); } void draw() {} void keyPressed() { switch(key) { case 'l': case 'L': println("Turning left"); break; case 'r': case 'R': println("Turning right"); break; } What does this do?

int positionX = 250; int positionY = 250; int deltaX = 0; int deltaY = 0; void setup() { size(500, 500); smooth(); } void draw() { background(255); positionX = positionX + deltaX; positionY = positionY + deltaY; if (positionX < 0) positionX = 0; if (positionX > width) positionX = width; if (positionY < 0) positionY = 0; if (positionY > height) positionY = height; ellipse(positionX, positionY, 50, 50); } void keyPressed() { switch (keyCode) { case 37: deltaX = -2; deltaY = 0; break; case 39: deltaX = 2; deltaY = 0; break; case 38: deltaY = -2; deltaX = 0; break; case 40: deltaY = 2; deltaX = 0; break; case 32: deltaX = 0; deltaY = 0; break; }