Module 01 Processing Recap

Similar documents
Module 01 Processing Recap. CS 106 Winter 2018

Module 05 User Interfaces. CS 106 Winter 2018

Variables. location where in memory is the information stored type what sort of information is stored in that memory

CISC 1600 Lecture 3.1 Introduction to Processing

Pick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1

Conditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

1 Getting started with Processing

Watch the following for more announcements

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CST112--Functions Page 1

[ the academy_of_code] Senior Beginners

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Variables One More (but not the last) Time with feeling

CISC 1600, Lab 2.2: Interactivity in Processing

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

Basic Computer Programming (Processing)

CISC 1600, Lab 3.2: Interactivity in Processing

Appendix: Common Errors

Solution Notes. COMP 151: Terms Test

CS 101 Media (Images, Video, etc) Lecture 20

GRAPHICS & INTERACTIVE PROGRAMMING. Lecture 1 Introduction to Processing

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

Introduction to Processing

CSCE 110 Dr. Amr Goneid Exercise Sheet (6): Exercises on Structs and Dynamic Lists

mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut

Interaction Design A.A. 2017/2018

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Pointers and scanf() Steven R. Bagley

CS 106 Winter 2016 Craig S. Kaplan. Module 01 Processing Recap. Topics

Exploring Processing

Variables and Control Structures. CS 110 Eric Eaton

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

Miscellaneous Stuff That Might Be Important.

Loops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2

A B C D CS105 03a Interaction

Recall that creating or declaring a variable can be done as follows:

CS 101 Functions. Lecture 15

CSE120 Wi18 Final Review

1 Getting started with Processing

Bits and Bytes. How do computers compute?

What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username

Using Methods. Writing your own methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

We start by looking at a double cone. Think of this as two pointy ice cream cones that are connected at the small tips:

(Inter)Ac*ve Scripts. Sta*c Program Structure 1/26/15. Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

CST112 Looping Statements Page 1

Object-Oriented Programming Concepts

CISC 1600, Lab 3.1: Processing

if / if else statements

Chapter 5. Condi.onals

+ Questions about Assignment 5?

We will start our journey into Processing with creating static images using commands available in Processing:

CISC 1600, Lab 2.1: Processing

Processing Assignment Write- Ups

Final Exam Winter 2013

Evaluating Logical Expressions

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Khan Academy JavaScript Study Guide

What is a variable? A named locajon in the computer s memory. A variable stores values

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

The way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

CMPT-166: Sample Midterm

CS/ENGRD 2110 SPRING 2018

Topic 7: Algebraic Data Types

Interaction Design A.A. 2017/2018

Iteration in Programming

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

More C++ : Vectors, Classes, Inheritance, Templates

Contents A Little C++

ITI Introduction to Computing II

Repetition is the reality and the seriousness of life. Soren Kierkegaard

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

ITI Introduction to Computing II

Practice exam for CMSC131-04, Fall 2017

Perimeter, Area, Surface Area, & Volume

Fast Introduction to Object Oriented Programming and C++

CS 106 Winter 2016 Craig S. Kaplan. Module 08 Randomness and noise Topics

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

What can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts

COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9

Expressions and Casting

Introduction to Programming Using Java (98-388)

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Braitenberg code. Page 1

Introduction to Processing. Sally Kong

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

CS24 Week 3 Lecture 1

G Programming Languages - Fall 2012

CS 177 Week 15 Recitation Slides. Review

Chapter 4 Defining Classes I

Perry Bible Fellowship [pbfcomics.com/94/]

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Pure Math 30: Explained!

Chapter 12: Functions Returning Booleans and Collision Detection

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

Collisions/Reflection

Transcription:

Module 01 Processing Recap

Processing is a language a library an environment

Variables A variable is a named value. It has a type (which can t change) and a current value (which can change).

Variables A declaration introduces a new variable, and optionally gives it an initial value. int a; float b = 6.28; boolean c = b > 19; Three declarations

Variables A declaration introduces a new variable, and optionally gives it an initial value. int a; float b = 6.28; boolean c = b > 19; Type

Variables A declaration introduces a new variable, and optionally gives it an initial value. int a; float b = 6.28; boolean c = b > 19; Name

Variables A declaration introduces a new variable, and optionally gives it an initial value. int a; float b = 6.28; boolean c = b > 19; Initial value

Variables Say a variable s name to read from it. Use assignment (=) to write to it. Processing includes many built-in names. True constants can t be changed. Some variables are meant to be readonly. Some are updated automatically, and are meant to be read repeatedly.

Scope Every declaration in Processing has a scope: the part of the program source code in which that declaration is valid. Usually either global or bounded by the nearest enclosing. Scope is a complicated topic. If in doubt, just avoid re-using the same names!

Control flow By default, Processing will execute statements in the order they re given. Control flow can modify that order.

Conditionals if( keypressed && key == ' ' ) ellipse( mousex, mousey, 20, 20 ); An if statement

Conditionals Condition if( keypressed && key == ' ' ) ellipse( mousex, mousey, 20, 20 );

Conditionals if( keypressed && key == ' ' ) ellipse( mousex, mousey, 20, 20 ); Body

Conditionals if( keypressed && key == ' ' ) ellipse( mousex, mousey, 20, 20 ); else rect( mousex, mousey, 20, 20 );

Conditionals if ( keypressed ) if ( key == 'e' ) ellipse( mousex, mousey, 20, 20 ); else if ( key == 'l' ) line( 10, 10, 100, 100 ); else rect( mousex, mousey, 20, 20 );

While loops int y = 0; while( y < height ) line( 0, y, width, y ); y = y + 10;

While loops int y = 0; Condition while( y < height ) line( 0, y, width, y ); y = y + 10;

While loops int y = 0; while( y < height ) line( 0, y, width, y ); y = y + 10; Body

While loops int y = 0; while( y < height ) line( 0, y, width, y ); y = y + 10; Update!

For loops for( int y = 0; y < height; y += 10 ) line( 0, y, width, y );

For loops Initializer for( int y = 0; y < height; y += 10 ) line( 0, y, width, y );

For loops Condition for( int y = 0; y < height; y += 10 ) line( 0, y, width, y );

For loops Update for( int y = 0; y < height; y += 10 ) line( 0, y, width, y );

For loops for( int y = 0; y < height; y += 10 ) line( 0, y, width, y ); Body

Functions A function gives a name to a computation. Benefits: Ease of (error-free) repetition. Encapsulation: hide the messy details. Abstraction: think about problem solving at a higher level. Establish a point of connection between parts of a program.

(x3,y3) (x2,y2) (x1,y1) Calculate the perimeter of a triangle.

Pythagorean theorem

(x3,y3) (x2,y2) (x1,y1) float e1 = sqrt( sq( x2 - x1 ) + sq( y2 - y1 ) ); float e2 = sqrt( sq( x3 - x2 ) + sq( y3 - y2 ) ); float e3 = sqrt( sq( x1 - x3 ) + sq( y1 - y3 ) ); float perim = e1 + e2 + e3;

float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) );

Return type float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) );

Function name float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) );

Parameters float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) );

float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) ); Body

float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) ); Return statement

ax bx cx dx answer float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) );

(x3,y3) (x2,y2) (x1,y1) float e1 = sqrt( sq( x2 - x1 ) + sq( y2 - y1 ) ); float e2 = sqrt( sq( x3 - x2 ) + sq( y3 - y2 ) ); float e3 = sqrt( sq( x1 - x3 ) + sq( y1 - y3 ) ); float perim = e1 + e2 + e3;

(x3,y3) (x2,y2) (x1,y1) float measure( float ax, float ay, float bx, float by ) return sqrt( sq( bx - ax ) + sq( by - ay ) ); float e1 = measure( x1, y1, x2, y2 ); float e2 = measure( x2, y2, x3, y3 ); float e3 = measure( x3, y3, x1, y1 ); float perim = e1 + e2 + e3;

(x3,y3) (x2,y2) (x1,y1) float e1 = dist( x1, y1, x2, y2 ); float e2 = dist( x2, y2, x3, y3 ); float e3 = dist( x3, y3, x1, y1 ); float perim = e1 + e2 + e3;

float triangleperim( float x1, float y1, float x2, float y2, float x3, float y3 ) float e1 = dist( x1, y1, x2, y2 ); float e2 = dist( x2, y2, x3, y3 ); float e3 = dist( x3, y3, x1, y1 ); return e1 + e2 + e3;

Functions A function takes 0 or more parameters as input and returns 0 or 1 values as output. 0 parameters 1+ parameters No return value Universal command! Contingent command Return value Retrieve hidden information Calculate something

Hooks Processing knows about a few predetermined function names. If you define functions (hooks) with those names, Processing will call them at the right times. Some libraries add more hooks.

Arrays An array is a sequence of values, all of the same type, bundled into a single master value. float[] temps = -4.8, -4.79, -4.764, -4.762, -4.764, -4.824, /* 86 more numbers... */ -1.083, -1.2, -1.3, -1.41 ;

Arrays An array is a sequence of values, all of the same type, bundled into a single master value. Array type float[] temps = -4.8, -4.79, -4.764, -4.762, -4.764, -4.824, /* 86 more numbers... */ -1.083, -1.2, -1.3, -1.41 ;

float[] temps = -4.8, -4.79, -4.764, -4.762, -4.764, -4.824, /* 86 more numbers... */ -1.083, -1.2, -1.3, -1.41 ; for( int idx = 0; idx < temps.length; ++idx ) if( temps[idx] > 0.0 ) println( "Where's my sunscreen?" );

float[] temps = -4.8, -4.79, -4.764, -4.762, -4.764, -4.824, /* 86 more numbers... */ -1.083, -1.2, -1.3, -1.41 ; Array size for( int idx = 0; idx < temps.length; ++idx ) if( temps[idx] > 0.0 ) println( "Where's my sunscreen?" );

float[] temps = -4.8, -4.79, -4.764, -4.762, -4.764, -4.824, /* 86 more numbers... */ -1.083, -1.2, -1.3, -1.41 ; for( int idx = 0; idx < temps.length; ++idx ) if( temps[idx] > 0.0 ) println( "Where's my sunscreen?" ); Element access

Classes and objects A class introduces a new type. Values of that type (instances) have their own state and behaviour.

class Circle float cx; float cy; float radius; Circle( float cxin, float cyin, float radiusin ) cx = cxin; cy = cyin; radius = radiusin; void draw() ellipse( cx, cy, 2*radius, 2*radius );

class Circle Type name float cx; float cy; float radius; Circle( float cxin, float cyin, float radiusin ) cx = cxin; cy = cyin; radius = radiusin; void draw() ellipse( cx, cy, 2*radius, 2*radius );

class Circle float cx; float cy; float radius; Fields (per-instance state) Circle( float cxin, float cyin, float radiusin ) cx = cxin; cy = cyin; radius = radiusin; void draw() ellipse( cx, cy, 2*radius, 2*radius );

class Circle float cx; float cy; float radius; Constructor (initialize state) Circle( float cxin, float cyin, float radiusin ) cx = cxin; cy = cyin; radius = radiusin; void draw() ellipse( cx, cy, 2*radius, 2*radius );

class Circle float cx; float cy; float radius; Circle( float cxin, float cyin, float radiusin ) cx = cxin; cy = cyin; radius = radiusin; Method (behaviour) void draw() ellipse( cx, cy, 2*radius, 2*radius );

Circle[] circs; void setup() circs = new Circle[10]; for ( int idx = 0; idx < circs.length; ++idx ) circs[idx] = new Circle( random(100), random(100), random(20) ); void draw() background( 255 ); for ( int idx = 0; idx < circs.length; ++idx ) circs[idx].draw();

null null is a special keyword that represents a nonexistent value for every class. It is the default value for variables of class type. It s illegal to access any fields or methods of null. void draw() background( 255 ); for ( int idx = 0; idx < circs.length; ++idx ) if ( circs[idx]!= null ) circs[idx].draw();

void getintersection( Line l1, Line l2 ) if(... ) return new Point(...,... ); else return null;

What s this? this is a keyword that can be used inside the body of a method. It always refers to the object that received the method call. We won t need it ourselves, but we ll see it sometimes when using libraries. import processing.video.*; Capture cam; void setup() cam = new Capture( this, 320, 240 ); cam.start();

What s this? this is a keyword that can be used inside the body of a method. It always refers to the object that received the method call. We won t need it ourselves, but we ll see it sometimes when using libraries. import processing.video.*; Capture cam; void setup() cam = new Capture( this, 320, 240 ); cam.start(); Jacques Carelman, Coffeepot for Masochists