Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values
|
|
- Joan Casey
- 5 years ago
- Views:
Transcription
1 Functions parameters return values 06 Functions 1 Functions Code that is packaged so it can be run by name Often has parameters to change how the function works (but not always) Often performs some computation and returns a value (but not always) We use functions all the time in Processing nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); We can also define our own custom functions 06 Functions 2
2 Why Custom Functions? Custom functions make code modular Modular code is: - easier - easier to reuse to test Credit: Credit: 06 Functions 3 Anatomy of a Function without Parameters void means it returns nothing function name empty brackets means no parameters void tree() { nostroke(); // trunk fill(#5a3709); // brown quad(45, 40, 55, 40, 60, 90, 40, 90); // leaves fill(#5cbf17); // green ellipse(50, 30, 55, 55); 06 Functions 4
3 landscape1 void draw() { coding tree(); function comments // draw tree // with bottom of trunk at 50, 90 void tree() { nostroke(); // trunk fill(#5a3709); quad(45, 40, 55, 40, 60, 90, 40, 90); // leaves fill(#5cbf17); // green ellipse(50, 30, 55, 55); 06 Functions 5 Calling Functions You must call your custom functions or they won t execute Processing calls setup and draw for you - setup and draw are built-in functions that you customize Defining Functions Define your functions outside setup and draw - the same place global variables are defined 06 Functions 6
4 function is called function returns 06 Functions 7 (demos) declaration order doesn't matter void printb() { print("b "); printa(); print("setup "); printb(); void printa() { print("a "); 06 Functions 8
5 What does this Output? print("apple "); saybanana(); sayorange(); void sayorange() { print("orange "); void saybanana() { print("banana "); A. apple B. orange C. banana orange D. apple orange banana E. apple banana orange 06 Functions 9 Anatomy of a Function with Parameters void means it returns nothing function name function parameters void tree(float x, float y) { nostroke(); // trunk fill(#5a3709); // brown quad(x - 5, y - 50, x + 5, y - 50, x + 10, y, x - 10, y); // leaves fill(#5cbf17); // green ellipse(x, y - 60, 55, 55); 06 Functions 10
6 Function Arguments function name arguments tree(40, 150); 06 Functions 11 landscape2... coding // use the tree function to // create a forest tree(40, 90); tree(100, 90); tree(160, 90); function comments // draw tree // x, y position (centre bottom of trunk) void tree(float x, float y) { nostroke(); // trunk fill(#5a3709); // brown quad(x - 5, y - 50, x + 5, y - 50, x + 10, y, x - 10, y); // leaves fill(#5cbf17); // green ellipse(x, y - 60, 55, 55); 06 Functions 12
7 06 Functions 13 What does this Output? fruit(-1); print("apple "); void fruit(int a) { if (a > 0) { print("orange "); else { print("banana "); A. apple B. fruit apple C. banana apple D. orange apple E. orange banana apple 06 Functions 14
8 Calling Functions You must call your custom functions or they won t execute Processing calls setup and draw for you - setup and draw are built-in functions that you customize Defining Functions Define your functions outside setup and draw - the same place global variables are defined You cannot define more than one custom function with the same name and same parameter types 06 Functions 15 Defining Multiple Functions with Same Name void tree() {... void tree(float x, float y) {... void tree(float x) {... void tree(float treex, float treey) { Functions 16
9 float vs. int parameters These are different functions void tree(float x, float y) {... void tree(int x, int y) { Functions 17 Function Signature the signature of a function is: - the function name - the parameter types (in order) These are all different function signatures: void tree() void tree(float x) void tree(float x, float y) void tree(int x, int y) void tree(boolean b, int a) void tree(int a, boolean b) the order of parameter types is different, so different signatures 06 Functions 18
10 vehicle // draw a vehicle // x, y is position of centre bottom // hue hue to fill the car body // (0 to 360 degrees) void vehicle(int x, int y, float hue) { // top part stroke(0); fill(hue, 100, 100); // orange rect(x - 20, y - 40, 40, 30); fill(150); // gray // front wheel ellipse(x - 20, y - 10, 20, 20); // back wheel ellipse(x + 20, y - 10, 20, 20); 06 Functions Functions 20
11 Function attributes are passed-by-value passed-by-value means the function parameter is a copy of an attribute variable changing the value of a parameter will not change the attribute variable int a = 10; println(a); // 10 f(a); println(a); // 10 int a = 10; println(a); // 10 f(a); println(a); // 10 void f(int b) { b = b + 1; void f(int a) { a = a + 1; 06 Functions 21 Functions and Scope Custom functions can access global variables, (just like setup and draw) Custom functions can have local variables, (just like setup and draw) 06 Functions 22
12 landscape3 // draw trees behind with a for loop for (float x = 50; x < width; x += 100) { tree(x, 90);... // draw the car vehicle(vehiclex, 92, vehiclehue); // draw trees in front with a while loop float x = 100; while (x < width) { tree(x, 95); x = x + 100; 06 Functions 23 What will you see? void draw() { a(); ellipse(25, 50, 50, 50); b(); ellipse(75, 50, 50, 50); void a() { strokeweight(10); fill(128); // grey void b() { strokeweight(2); fill(255); // white A C B D nothing, it s an error 06 Functions 24
13 What will you see? void draw() { a(); ellipse(25, 50, 50, 50); b(); ellipse(75, 50, 50, 50); void a() { strokeweight(10); fill(128); // grey b(); void b() { strokeweight(2); fill(255); // white A C B D nothing, it s an error 06 Functions 25 returns nothing void myfunc(float a, floa returns something int myfunc(float a, floa 06 Functions 26
14 Functions that Return Values We use functions that return values all the time: float x = random(1, 100); float a = map(x, 1, 200, 20, 30); fill(random(255)); arc(0, 0, 10, 10, 0, radians(45)); 06 Functions 27 A Function with a Return Value float is the return type function name function parameters float sum (float a, float b, float c) {... return ; this is where the value is returned 06 Functions 28
15 Example return type is int int sum(int a, int b, int c) { int total = a + b + c; return total; required return statement 06 Functions 29 Function Calling Tracethrough int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 30
16 Trace int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 31 Trace int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 32
17 Trace int answer = sum(1, 2, 3); a = 1 b = 2 c = 3 int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 33 Trace int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 34
18 Trace int answer = sum(1, 2, 3); total = 6 int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 35 Trace int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 36
19 Trace int answer = sum(1, 2, 3); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 37 Trace int answer = sum(1, 2, 3); sum(1, 2, 3) = 6 int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 38
20 Trace int answer = sum(1, 2, 3); answer = 6 int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 39 Analogy setup() sum( ) 06 Functions 40
21 Analogy a = 1 b = 2 c = 3 setup() sum( ) 06 Functions 41 Analogy a + b + c setup() sum( ) 06 Functions 42
22 Analogy 6 setup() sum( ) 06 Functions 43 Analogy setup() sum( ) 06 Functions 44
23 sumfunction int x = sum(2, 4, 6);... int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 45 sumfunction int x = sum(2, 4, 6); int y = sum(23, 45, 71) / 2; int z = sum(x, y, 10); line(0, 0, width, sum(x, y, z)); int sum(int a, int b, int c) { int total = a + b + c; return total; 06 Functions 46
24 Using Functions with Return Values Can use function that returns values anywhere you use the same type of value, e.g. // a = 12 int a = sum(2, 4, 6); // b = 12 * 100 b = sum(2, 4, 6) * 100; // c = ( ) c = sum(2, 4, sum(2, 4, 6)); // point(12, 10) point(sum(2, 4, 6), 10); // if (4 > 3) {... if (sum(2, 4, 6) > 3) { Functions 47 What does this Output? print(double(1)); int double(int a) { int r = a + a; return r; A. 1 B. 2 C. r D. double E. nothing, it s a syntax error 06 Functions 48
25 What does this Output? print(double(double(1))); int double(int a) { int r = a + a; return r; A. 1 B. 2 C. 3 D. 4 E. nothing, it s a syntax error 06 Functions 49 What does this Output? print(triple(1)); int triple(int a) { int r = a + a + a; A. 1 B. 2 C. 3 D. 4 E. It s a syntax error 06 Functions 50
26 Possible Logic Error Need to assign the return value to something - it may be a logic error if you don t sum(3, 6, 9); // nothing assigned random(1, 1000); // nothing assigned 06 Functions 51 Defining Multiple Functions with Same Name int sum(int a, int b, int c) {... int sum(int a, int b, int c, int d) {... float sum(int a, int b, int c) {... void sum(int a, int b, int c) {... can t have same name with same parameters but different return types 06 Functions 52
27 mymax1 // returns the largest number (a or b) float mymax(float a, float b) { float largest; if (a > b) { largest = a; else { largest = b; return largest; 06 Functions 53 mymax (unit tests) // unit tests println(mymax(5, 10)); // answer is 10 println(mymax(15, 10)); // answer is 15 println(mymax(-500, 10)); // answer is 10 println(mymax(0.5, 0.1)); // answer is 0.5 println(mymax(10, 10)); // answer is Functions 54
28 mymax2 (early return) // returns the largest number (a or b) float mymax(float a, float b) { if (a > b) { return a; else { return b; 06 Functions 55 Processing has built-in functions max and min can accept 2 or 3 arguments returns float or int depending what argument types closely related to constrain max(a, b) max(a, b, c) min(a, b) min(a, b, c) 06 Functions 56
29 Circle Hit Testing (Bounds Detection) Radius is the distance between circle centre to circle edge If distance from mouse to circle center is less than radius, then circle is hit (e.g. rollover, clicked on, etc.) 06 Functions 57 Distance Between Two Points strokeweight(10); point(77, 81); // P point(13, 45); // Q // calculate distance // between point P and Q float d = how to do this? 06 Functions 58
30 Pythagorean Theorem 06 Functions 59 mydist use built-in function sqrt() for square root // returns the distance between // point P at (px, py) and point Q at (qx, qy) float mydist(float px, float py, float qx, float qy) { float a = px - qx; float b = py - qy; float d = sqrt((a * a) + (b * b)); return d; 06 Functions 60
31 circlehittest // returns true if px, py is inside a circle // that is centred at cx, cy with radius r boolean circlehittest(float px, float py, float cx, float cy, float r) { float d = mydist(px, py, cx, cy); if (d < r) { return true; else { return false; 06 Functions 61 Processing has a built-in function for distance returns float dist(x1, y1, x2, y2) Use this built-in dist function to calculate the distance between two points in your labs and assignments! 06 Functions 62
32 Extra: Mouse Speed The distance between the current mouse position and the previous mouse position is the speed of the mouse - pmousex and pmousey are built-in global variables for the previous mouse position float speed = dist(mousex, mousey, pmousex, pmousey); since we calculate it each time draw is called, the speed will be in pixels per frame - since framerate is 60 frames per second, multiply by 60 to get pixels per second 06 Functions 63 maxspeed float maxspeed = 0; void draw() { background(245); // almost white float speed = dist(mousex, mousey, pmousex, pmousey); // update the max speed so far if (speed > maxspeed) { maxspeed = speed; // display the max speed and current speed fill(0); // black text(round(maxspeed), width / 2, height / 2-40); text(round(speed), width / 2, height / ); 06 Functions 64
33 mousespeed size(300, 300); nostroke(); background(245); // almost white void draw() { float speed = dist(mousex, mousey, pmousex, pmousey); // draw an ellipse with size representing speed fill(0, 50); // semi transparent black ellipse(mousex, mousey, speed, speed); 06 Functions 65
Loops. Variable Scope Remapping Nested Loops. Donald Judd. CS Loops 1. CS Loops 2
Loops Variable Scope Remapping Nested Loops CS105 05 Loops 1 Donald Judd CS105 05 Loops 2 judd while (expression) { statements CS105 05 Loops 3 Four Loop Questions 1. What do I want to repeat? - a rect
More informationPick a number. Conditionals. Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary. CS Conditionals 1
Conditionals Boolean Logic Relational Expressions Logical Operators Numerical Representation Binary CS105 04 Conditionals 1 Pick a number CS105 04 Conditionals 2 Boolean Expressions An expression that
More information1. Complete these exercises to practice creating user functions in small sketches.
Lab 6 Due: Fri, Nov 4, 9 AM Consult the Standard Lab Instructions on LEARN for explanations of Lab Days ( D1, D2, D3 ), the Processing Language and IDE, and Saving and Submitting. Rules: Do not use the
More informationA B C D CS105 03a Interaction
Interaction Function Definition Events Built-in Variables CS105 03a Interaction 1 Which image is drawn by this code? strokeweight(10); stroke(0, 255, 0); // green line(99, 0, 0, 99); stroke(200, 0, 200);
More informationWatch the following for more announcements
Review "plain text file" loadstrings() split() splittokens() selectinput() println(), float(), int(), can take an array argument, will return an array easy way to convert an array of Strings to an array
More informationWhat is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username
What is a variable? a named location in the computer s memory mousex mousey width height fontcolor username Variables store/remember values can be changed must be declared to store a particular kind of
More informationBasic Computer Programming (Processing)
Contents 1. Basic Concepts (Page 2) 2. Processing (Page 2) 3. Statements and Comments (Page 6) 4. Variables (Page 7) 5. Setup and Draw (Page 8) 6. Data Types (Page 9) 7. Mouse Function (Page 10) 8. Keyboard
More information(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
(Inter)Ac*ve Scripts Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar Slides revised by Michael Goldwasser Sta*c Program Structure // Create and set canvas size(width,
More informationUsing Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Using Methods Methods that handle events Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Caveat The term function is used in Processing e.g. line(),
More informationSolution Notes. COMP 151: Terms Test
Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms
More informationWhat can we do with Processing? Let s check. Natural Language and Dialogue Systems Lab Guest Image. Remember how colors work.
MIDTERM REVIEW: THURSDAY I KNOW WHAT I WANT TO REVIEW. BUT ALSO I WOULD LIKE YOU TO TELL ME WHAT YOU MOST NEED TO GO OVER FOR MIDTERM. BY EMAIL AFTER TODAY S CLASS. What can we do with Processing? Let
More information+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.
+ Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create
More informationmith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Important Review Does the animation leave a trace? Are the moving objects move without a
More informationBits and Bytes. How do computers compute?
Bits and Bytes How do computers compute? Representing Data All data can be represented with: 1s and 0s on/of true/false Numbers? Five volunteers... Binary Numbers Positional Notation Binary numbers use
More informationInteraction Design A.A. 2017/2018
Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 7 Conditionals in Processing Francesco Leotta, Andrea Marrella
More informationModule 01 Processing Recap
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
More informationQuestion 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels:
Question 1 (10 points) Write the correct answer in each of the following: a) Write a Processing command to create a canvas of 400x300 pixels: size(400, 300); b) After the above command is carried out,
More informationModule 01 Processing Recap. CS 106 Winter 2018
Module 01 Processing Recap CS 106 Winter 2018 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
More informationKimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013
1. A first program // Create 200x200 canvas // Print favorite quote size(200, 200); println("it is what it is"); // Draw rectangle and a line rect(100,100,50,50); line(0,0,50,50); // Save as.pde. Can be
More informationChapter 5. Condi.onals
Chapter 5 Condi.onals Making Decisions If you wish to defrost, press the defrost bu=on; otherwise press the full power bu=on. Let the dough rise in a warm place un.l it has doubled in size. If the ball
More informationCISC 1600, Lab 3.1: Processing
CISC 1600, Lab 3.1: Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using OpenProcessing, a site for building processing sketches online using processing.js. 1.1. Go to https://www.openprocessing.org/class/57767/
More informationPractice Written Examination, Fall 2016 Roger B. Dannenberg, instructor
15-104 Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor Possibly useful function signatures (italics mean an expression goes here ): createcanvas(w, h); width height key background(r,
More informationWe will start our journey into Processing with creating static images using commands available in Processing:
Processing Notes Chapter 1: Starting Out We will start our journey into Processing with creating static images using commands available in Processing: rect( ) line ( ) ellipse() triangle() NOTE: to find
More informationExploring Processing
Exploring Processing What is Processing? Easy-to-use programming environment Let s you edit, run, save, share all in one application Designed to support interactive, visual applications Something we ve
More informationWhat is a variable? A named locajon in the computer s memory. A variable stores values
Chapter 4 Summary/review coordinate system basic drawing commands and their parameters (rect, line, ellipse,background, stroke, fill) color model - RGB + alpha Processing IDE - entering/saving/running
More informationVariables. location where in memory is the information stored type what sort of information is stored in that memory
Variables Processing, like many programming languages, uses variables to store information Variables are stored in computer memory with certain attributes location where in memory is the information stored
More informationFinal Exam Winter 2013
Final Exam Winter 2013 1. Which modification to the following program makes it so that the display shows just a single circle at the location of the mouse. The circle should move to follow the mouse but
More informationAn Introduction to Processing
An Introduction to Processing Creating static drawings Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Coordinate System in Computing.
More information1 Getting started with Processing
cisc3665, fall 2011, lab I.1 / prof sklar. 1 Getting started with Processing Processing is a sketch programming tool designed for use by non-technical people (e.g., artists, designers, musicians). For
More informationUniversity of Cincinnati. P5.JS: Getting Started. p5.js
p5.js P5.JS: Getting Started Matthew Wizinsky University of Cincinnati School of Design HTML + CSS + P5.js File Handling & Management Environment Canvas Coordinates Syntax Drawing Variables Mouse Position
More informationThe way I feel about music is that there is no right and wrong. Only true and false. Fiona Apple. true false false
5 Conditionals Conditionals 59 That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted. George Boole The way I feel about music
More informationCISC 1600, Lab 2.1: Processing
CISC 1600, Lab 2.1: Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using Sketchpad, a site for building processing sketches online using processing.js. 1.1. Go to http://cisc1600.sketchpad.cc
More informationUsing Methods. More on writing methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics
Using Methods More on writing methods Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topics list Method example: Eyes Method example: X s Overloading
More informationThe Processing language. Arduino and Processing.
IAT267 Introduc/on to Technological Systems Lecture 8 The Processing language. Arduino and Processing. 1 Course Project All teams submibed very interes/ng proposals One requirement for the project is to
More information2D Shapes. Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar
2D Shapes Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar Did you do this? Read Chapter 2 (pages 33-50) Read and do the Coordinate Systems & Shapes and Color tutorials
More informationConditional Events. Mouse events and Operators. Dr. Siobhán Drohan Mairead Meagher. Produced by:
Conditional Events Mouse events and Operators Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topics list Mouse Events Recap: Arithmetic Operators
More informationif / if else statements
if / if else statements December 1 2 3 4 5 Go over if notes and samples 8 9 10 11 12 Conditionals Quiz Conditionals TEST 15 16 17 18 19 1 7:30 8:21 2 8:27 9:18 3 9:24 10:14 1 CLASS 7:30 8:18 1 FINAL 8:24
More informationCS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions
CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions The exam will be closed-note and closed-book; please consider this fact before using your notes on this practice version. Please see
More informationCS 101 Functions. Lecture 15
CS 101 Functions Lecture 15 1 Key Processing language features so-far Basic color/shapes drawing Variables For-loops If-statements 2 Functions In the next few days, we ll be talking about Functions A Function
More informationOld 257 Exam #2s for Practice
Old Exam #2s 257/757 Exploring Programming with Graphics Page 1 Old 257 Exam #2s for Practice Exams will be taken on Thursday March 27 in the cluster. You will have the entire class time to do the exam.
More informationIteration in Programming
Iteration in Programming for loops Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list There are three types of loop in programming: While
More informationInteraction Design A.A. 2017/2018
Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 5 Basics of Processing Francesco Leotta, Andrea Marrella Last update
More informationClass #1. introduction, functions, variables, conditionals
Class #1 introduction, functions, variables, conditionals what is processing hello world tour of the grounds functions,expressions, statements console/debugging drawing data types and variables decisions
More informationCST112--Functions Page 1
CST112--Functions Page 1 1 2 3 4 5 6 7 8 Processing: Functions CST112 Structuring Programs (Modularity) Programmers often divide large applications into several modules within program This is necessary
More informationCOMP Summer 2015 (A01) Jim (James) Young jimyoung.ca
COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca Don t use == for floats!! Floating point numbers are approximations. How they are stored inside the computer means that
More informationThis unit introduces the basics of trigonometry and how to utilize it for generating form.
Math 3: Trigonometry This unit introduces the basics of trigonometry and how to utilize it for generating form. Syntax introduced: PI, QUARTER_PI, HALF_PI, TWO_PI, radians(), degrees() sin(), cos(), arc()
More informationIntroduction to Processing. Sally Kong
Introduction to Processing Sally Kong - Open Source Platform - Geared toward creating visual, interactive media - Created by Ben Fry and Casey Reas Basic Setup void setup() { size(800, 600); background(255);
More informationInteraction Design A.A. 2017/2018
Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 8 Loops and Arrays in Processing Francesco Leotta, Andrea Marrella
More informationCISC 1600 Lecture 3.1 Introduction to Processing
CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists
More informationThe Junior Woodchuck Manuel of Processing Programming for Android Devices
Page1of15 TheJuniorWoodchuck Manuel of ProcessingProgramming for AndroidDevices TheImage JuniorWoodchuckManuelforProcessingProgramming Version1 CopyrightDavidNassarandJimRoberts,December2011,PittsburghPA
More informationLecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.
Lecture 05: Methods AITI Nigeria Summer 2012 University of Lagos. Agenda What a method is Why we use methods How to declare a method The four parts of a method How to use (invoke) a method The purpose
More informationCMPT-166: Sample Midterm
CMPT 166, Fall 2016, Surrey Sample Midterm 1 Page 1 of 11 CMPT-166: Sample Midterm Last name exactly as it appears on your student card First name exactly as it appears on your student card Student Number
More informationGRAPHICS & INTERACTIVE PROGRAMMING. Lecture 1 Introduction to Processing
BRIDGES TO COMPUTING General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. This work is licensed under the Creative Commons Attribution-ShareAlike
More informationModule 05 User Interfaces. CS 106 Winter 2018
Module 05 User Interfaces CS 106 Winter 2018 UI is a big topic GBDA 103: User Experience Design UI is a big topic GBDA 103: User Experience Design CS 349: User Interfaces CS 449: Human-Computer Interaction
More informationBraitenberg code. Page 1
// Processing source code : Braitenberg's Vehicles // Based on program written by william ngan // SensoryField class stub coded by Prof. Mateas and Mayhew Seavey in 2004... //...and
More informationProcessing & Arduino in Tandem. Creating Your Own Digital Art Tools
Processing & Arduino in Tandem Creating Your Own Digital Art Tools Week 2 - Making your own drawing tool Using Processing to build a basic application Segment 1 - A Basic Drawing Program Change window
More informationComputer Graphics. Interaction
Computer Graphics Interaction Jordi Linares i Pellicer Escola Politècnica Superior d Alcoi Dep. de Sistemes Informàtics i Computació jlinares@dsic.upv.es http://www.dsic.upv.es/~jlinares processing allows
More informationCISC 1600 Lecture 2.2 Interactivity&animation in Processing
CISC 1600 Lecture 2.2 Interactivity&animation in Processing Topics: Interactivity: keyboard and mouse variables Interactivity: keyboard and mouse listeners Animation: vector graphics Animation: bitmap
More informationmith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Ben Fry on Processing... http://www.youtube.com/watch?&v=z-g-cwdnudu An Example Mouse 2D
More informationINTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen
INTRODUCTION TO PROCESSING Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen What is Processing? Processing is a programming language designed to make programming easier Developers were frustrated with
More informationRepetition is the reality and the seriousness of life. Soren Kierkegaard
6 Loops Loops 81 Repetition is the reality and the seriousness of life. Soren Kierkegaard What s the key to comedy? Repetition. What s the key to comedy? Repetition. Anonymous In this chapter: The concept
More informationCSE120 Wi18 Final Review
CSE120 Wi18 Final Review Practice Question Solutions 1. True or false? Looping is necessary for complex programs. Briefly explain. False. Many loops can be explicitly written out as individual statements
More informationCISC 1600, Lab 2.3: Processing animation, objects, and arrays
CISC 1600, Lab 2.3: Processing animation, objects, and arrays Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad. sketchpad.cc in your browser and log in. Go to http://cisc1600.
More informationProcessing Assignment Write- Ups
Processing Assignment Write- Ups Exercise 1-1 Processing is not an elaborate series of points like connect the dots or is it? Can t be cause I got it all wrong when I mapped out each and every point that
More information1 Getting started with Processing
cis3.5, spring 2009, lab II.1 / prof sklar. 1 Getting started with Processing Processing is a sketch programming tool designed for use by non-technical people (e.g., artists, designers, musicians). For
More informationCPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM
CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM Name: Student ID: Signature: Section (circle one): George Steve Your signature acknowledges your understanding of and agreement
More informationCOMP Summer 2015 (A01) Jim (James) Young jimyoung.ca
COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca final float MAX_SPEED = 10; final float BALL_SIZE = 5; void setup() { size(500, 500); void draw() { stroke(255); fill(255);
More informationAll program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.
With Solutions in Red CS110 Introduction to Computing Fall 2012 Section 2 Exam 1 This is an open notes exam. Computers are not permitted. Your work on this exam must be your own. Answer all questions in
More informationVariables One More (but not the last) Time with feeling
1 One More (but not the last) Time with feeling All variables have the following in common: a name a type ( int, float, ) a value an owner We can describe variables in terms of: who owns them ( Processing
More information+ Questions about Assignment 5?
+ Inheritance + Questions about Assignment 5? + Review n Objects n data fields n constructors n Methods n Classes + Using the Ball class Treat in a manner very similar to a primitive data type. Ball[]
More information[ the academy_of_code] Senior Beginners
[ the academy_of_code] Senior Beginners 1 Drawing Circles First step open Processing Open Processing by clicking on the Processing icon (that s the white P on the blue background your teacher will tell
More informationArrays. circleracers (one racer) Object Creation and "dot syntax" Array Operation Idiom. // the x-position of the racer float x = 0;
Arrays Object Creation and "dot syntax" Array Operation Idiom CS 105 08 Arrays 1 circleracers (one racer) // the x-position of the racer float x = 0; void draw() { background(245); // white drawracer(x,
More informationEXAMINATIONS 2017 TRIMESTER 2
EXAMINATIONS 2017 TRIMESTER 2 CGRA 151 INTRODUCTION TO COMPUTER GRAPHICS Time Allowed: TWO HOURS CLOSED BOOK Permitted materials: Silent non-programmable calculators or silent programmable calculators
More informationRecall that creating or declaring a variable can be done as follows:
Lesson 2: & Conditionals Recall that creating or declaring a variable can be done as follows:! float radius = 20;! int counter = 5;! string name = Mr. Nickel ;! boolean ispressed = true;! char grade =
More informationDrawing a Circle. 78 Chapter 5. geometry.pyde. def setup(): size(600,600) def draw(): ellipse(200,100,20,20) Listing 5-1: Drawing a circle
5 Transforming Shapes with Geometry In the teahouse one day Nasrudin announced he was selling his house. When the other patrons asked him to describe it, he brought out a brick. It s just a collection
More informationCOMP Summer 2015 (A01) Jim (James) Young jimyoung.ca
COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca Hello! James (Jim) Young young@cs.umanitoba.ca jimyoung.ca office hours T / Th: 17:00 18:00 EITC-E2-582 (or by appointment,
More informationWrite a program that draws this image. The ligle squares are 5x5. The screen is the default 100x100. It doesn t change.
Chapter 7 Func.ons Recap func.on call statements setup() and draw() variables: declara.on, use, assignment if-else loops: while & for various operators (arithme.c, boolean, rela.onal, shortcut versions)
More informationEXAMINATIONS 2016 TRIMESTER 2
EXAMINATIONS 2016 TRIMESTER 2 CGRA 151 INTRODUCTION TO COMPUTER GRAPHICS Time Allowed: TWO HOURS CLOSED BOOK Permitted materials: Silent non-programmable calculators or silent programmable calculators
More informationCISC 1600, Lab 3.2: Interactivity in Processing
CISC 1600, Lab 3.2: Interactivity in Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using OpenProcessing, a site for building processing sketches online using processing.js. 1.1.
More informationDesign Programming DECO2011
Design Programming DECO2011 Rob Saunders web: http://www.arch.usyd.edu.au/~rob e-mail: rob@arch.usyd.edu.au office: Room 274, Wilkinson Building Data, Variables and Flow Control What is a Variable? Computers
More informationLecture 5: Methods CS2301
Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int
More informationName CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.
Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise. There are 21 problems and 25 points total. There are multiple versions
More informationSimulation and User Interaction
Chapter 3 Simulation and User Interaction What is in This Chapter? This chapter explains the concepts behind very simple computer simulations. All examples are explained within a graphical context. The
More informationGetting Started in Java CIS 110
Getting Started in Java CIS 110 2 Your First Program Program name 3 Your First Program The 4 li es aside fro the System.out li e are o sidered the Scaffolding of the program. Section 1.1 4 Your First Program
More informationName CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.
Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam. There are 21 problems and 50 points total. The last 5 problems ask you to write short programs or code fragments. There are multiple
More informationBasic Input and Output
Basic Input and Output CSE 120 Spring 2017 Instructor: Justin Hsia Teaching Assistants: Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee Administrivia Assignments: Animal Functions due today (4/12) Reading
More informationCS110 Introduction to Computing Fall 2016 Practice Exam 1
CS110 Introduction to Computing Fall 2016 Practice Exam 1 The exam will be closed-note and closed-book; please consider this fact before using your notes on this practice version. Please see the abbreviated
More informationMethods (cont.) Chapter 7
Methods (cont.) Chapter 7 Defining Simple Methods ReturnType Iden&fier ( ParameterList ) { Body ReturnType is the type of value returned from the method/funcbon. IdenBfier is the name of the method/funcbon.
More informationVariables and Control Structures. CS 110 Eric Eaton
Variables and Control Structures CS 110 Eric Eaton Review Random numbers mousex, mousey setup() & draw() framerate(), loop(), noloop() Mouse and Keyboard interaccon Arcs, curves, bézier curves, custom
More informationQuestion 2. [5 points] Given the following symbolic constant definition
CS 101, Spring 2012 Mar 20th Exam 2 Name: Question 1. [5 points] Determine which of the following function calls are valid for a function with the prototype: void drawrect(int width, int height); Assume
More informationThe Processing language
The Processing language Developed by Ben Fry and Casey Reas at MIT in 2001 Related to the languages Logo and Java Free, open-source software processing.org contains many programming resources www.openprocessing.org
More informationChapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.
Chapter 5 Methods rights reserved. 0132130807 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. rights reserved. 0132130807 2 1 Problem int sum =
More informationBasic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns Previous lecture Basics of Scheme Expressions and associated values (or syntax and
More informationStep 1: Create A New Photoshop Document
Snowflakes Photo Border In this Photoshop tutorial, we ll learn how to create a simple snowflakes photo border, which can be a fun finishing touch for photos of family and friends during the holidays,
More informationSFPL Reference Manual
1 SFPL Reference Manual By: Huang-Hsu Chen (hc2237) Xiao Song Lu(xl2144) Natasha Nezhdanova(nin2001) Ling Zhu(lz2153) 2 1. Lexical Conventions 1.1 Tokens There are six classes of tokes: identifiers, keywords,
More informationTransform 1: Translate, Matrices
Transform 1: Translate, Matrices This unit introduces coordinate system transformations and explains how to control their scope. Syntax introduced: translate(), pushmatrix(), popmatrix() The coordinate
More informationUsing Methods. Writing your own methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics
Using Methods Writing your own methods Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topics list Recap of method terminology: Return type Method
More informationJava Methods. Lecture 8 COP 3252 Summer May 23, 2017
Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method
More informationCompsci 101 Fall 2015 Exam 1 Rubric. Problem 1 (24 points)
Compsci 101 Fall 2015 Exam 1 Rubric Problem 1 (24 points) Each answer is one point each. Spelling of int, integer doesn't matter. Similarly string, str doesn't matter. For the value column all answers
More informationEvaluating Logical Expressions
Review Hue-Saturation-Brightness vs. Red-Green-Blue color Decimal, Hex, Binary numbers and colors Variables and Data Types Other "things," including Strings and Images Operators: Mathematical, Relational
More information