if / if else statements

Size: px
Start display at page:

Download "if / if else statements"

Transcription

1 if / if else statements December Go over if notes and samples Conditionals Quiz Conditionals TEST :30 8:21 2 8:27 9:18 3 9:24 10:14 1 CLASS 7:30 8:18 1 FINAL 8:24 10:14 2 CLASS 7:30 8:18 2 FINAL 8:24 10:14 4 CLASS 7:30 7:37 4 FINAL 7:37 9: :20 11: :37 12:18 7 CLASS 12:24 12: :20 11: :37 12:18 6 CLASS 12:24 12: :20 11: :37 12:18 3 CLASS 12:24 12:45 5 CLASS 9:37 9:45 5 FINAL 9:45-11:35 7 EXAM 12:45 2:35 6 FINAL 12:45-2:35 3 FINAL 12:45-2:35 EOS: ED 1

2 if / if else statements Sometimes your code is to be executed based on a certain condition, not for every situation. For example, you want a red background IF r is pressed. A circle changes direction IF it hits the edge. Thus, we introduce a need for conditional statements. There are six relational operators in Processing. These are a lot like operators used in your math classes. greater than > greater than or equal to >= less than < less than or equal to <= equal to (IS IT equal to?) == not equal to (IS IT not equal to?)!= There are also three logical operators: and && or not! Note: There is no semicolon after an if statement. Placing a semicolon there, means if true do nothing. It basically negates the if statement. The else is optional. VERY IMPORTANT: The compiler will execute just ONE STATEMENT following the if statement if the condition is true. Sometimes, you want to do more than one thing for a true or false statement. To execute more than one statement for a condition, you simply put the statements you would like executed inside curly brackets {}. This forces the compiler to treat the block of statements as if it were one statement. Examples: if (key == 'r') fill(255,0,0); else if (key == 'g') fill(0,255,0); else if (key == 'b') fill(0,0,255); else fill(255,255,0); if (key == 'r') { stroke(255,0,0); fill(255,0,0); } else if (key == 'g') { stroke(0,255,0); fill(0,255,0); } else if (key == 'b') { stroke(0,0,255); fill(0,0,255); } else { fill(255,255,0); stroke(255,255,0); } 2

3 Compound if statements: Compound conditions are used when 2 or more conditions are checked. Now open logicaloperators. In this program a rectangle is drawn based on the quadrant of the mouse location. To verify the quadrant, you must compare mousex to the width and mousey to the height. Open the following program samples: 1. ifkey: If a key is pressed, the fill command is executed. 2. ifkeymultiplelines: If a key is pressed, the stroke and fill commands are executed. 3. growshrinkcircle The diameter increases until it hits 400, then it decreases. 4. ifmouselocation A rectangle is drawn based on mouse location. 5. logicaloperators A rectangle is drawn in the quadrant of the mouse location 6. constrainrgb The color changes based on mouse location. The constrain command puts limits on RGB. PRACTICE: boolean right = false; boolean fast = false; int x = width / 2; int y = height / 2; //Write an if statement to move increment x by 2 if right is true, otherwise decrement x by 2. //Write an if statement to change right to false if x is within 50 of the width of the screen. //Write an if statement to change right to true if x is zero or less. //Write an if statement to change the fill color to yellow and the stroke to red if the key r is pressed. //Write an if statement for the following: If right is true and fast is true increment x by 5. If right is true and fast is false, //increment by 2. Do the same for if right is false, except decrement the x values. 3

4 Using keypressed Think about setup(). It runs only one time at the beginning of program execution. On the other hand, draw() runs continuously during execution. The keypressed method only runs when a key is pressed. You need to set a mode in keypressed and access it in draw. See the student sample for creating a boolean variable (true or false) that is set based on a key stroke and accessed in draw. Note, the draw method is necessary when using keypressed. Since setup() is only run at the moment you click run and never again, keypressed will not be detected without the draw() method; draw() forces your program to continuously run. Using Key Strokes and boolean variables: Daily Grade Edit mountainman to draw based on a key stroke. You should use the following key commands and draw accordingly. 1. g ground with road 2. c clouds (at least 3) 3. m 2 mountains 1 green-tone and 1 brown-tone that is snow capped 4. t tree use multiple ellipses to create full foliage 5. s stickman g was pressed to produce the image on the left. Now, c was pressed to add clouds. 4

5 m was pressed to add the mountains. t was pressed to add the tree. s was pressed to add the stickman. Coding your Program: READ THIS! You will need boolean variables for tree, mountain, clouds, stickman and ground In keypressed(): if (key == m ) mountain = true; if (key == s ) stickman == true; // and so on In draw(): if (mountain == true) mountains(); if (stickman == true) man(); so on. 5

6 Using Key Strokes and boolean variables continued You need to make your stickman move back and forth across your screen except he never goes off the screen. Make him move to and from 100 pixels from each side of your screen. You will need to add another boolean variable, movingleft, that is set to false in setup. You will also need to check the following in your code: Coding your Program: 1. Initialize his x location and movingleft in setup. 2. If movingleft is true, you will decrement your man s x value in man(). (He is moving left.) If movingleft is false, you will increment your man s value in man(). (He is moving right.) 3. If your stickman has an x value of 100 or less, you will change movingleft to false in man(). You want him to move right. 4. If your stickman has an x value within 100 of the width, you will change movingleft to true in man(). You want him to move left. Rubric: Keystrokes draw images: 50 Man stays on screen and changes directions: 50 6

7 Conditionals: Major Grade Coding your Program: 1. Open your movingcar from the previous unit. 2. You will need to add a boolean variable called day. You will also need to add 3 float variables, red, green and blue. Create an int value called speed. In setup(): 3. Set each of the colors to a random number up to 255 in setup. 4. Set day to true; 5. Set speed to 3. In car(): 6. Before you draw the car, change fill to draw in red, green blue. 7. Every time the car is off the screen (car s X value is greater than width plus length of car, plus more if you like), change the car s X value to a negative (so it is off the left side) and you need to generate new random values for red, green and blue, so it looks like a different car coming into view. 8. Increment the car s X value by speed, so it can fluctuate. In sky(): 9. If day is true, you do a light blue background and fill in yellow for the sun, else do a dark background and fill in white for the moon. 10. Every time the sun s X value is greater than the width, you will change the sun s X value to a negative, (so it off off the left side) and you need to change from day to night or night to day. To do this, use the following statement: day =!day; //Opposite of what it was In keypressed(): 11. Add code for the following: If f is pressed, set speed to 10. If s is pressed set speed to 3. If m is pressed, set speed to 5. 7

8 Adding a police car: The police car is in the other lane, going the opposite direction. 12. Add 3 int variables: px, py (the police car s x and y location), and policelightduration (the amount of time each of the red and blue lights is on). Add a boolean variable, redlight which is used to determine whether you are drawing the light in red (true) or blue (false). Lastly, add a PFont variable that is used for the font for the text on the police car. In setup(): 13. Initialize redlight to true. 14. Initialize the values for px and py. Be sure the police car is driving in one lane and your car in the other. 15. Initialize policelightduration to zero. 16. Create and set your font. Write policecar(): 17. Copy the code from car to policecar(); 18. The police car always goes fast. Speed is 10. Increment px by The light should be drawn before the body of the car. If redlight is true, fill with red, otherwise fill with blue. 20. If policelightduration is 20, set it back to zero and change redlight to opposite of its current state. (like #10) 21. Write POLICE on the side of the police car. 22. When the police car is off the screen on the left, change the police car s X value to a positive off the screen on the right. You may want the car to be ways off the screen so it is not constantly speeding down the road. 23. Increment policelightduration by 1. In draw(): 24. Call your policecar(). Set the color to white instead of a random color. RUBRIC: POINTS Cars continue to drive across screen with random colors: 25 Night changes to day and back again: 25 Car can go slow, medium or fast based on key stroke: 10 Police car s light changes from red to blue and back again: 20 Both cars drive in their own lane, but in opposite directions. 10 Police car drawn appropriately with POLICE on side: 10 8

9 Throwing Dice: Quiz Grade Directions: Write a program that will throw dice every time you click your mouse. In this program you must have a setup method, mousepressed method, and drawdice method. You need 5 global variables, one for each dice value. setup: Sets the screen size, set the rectmode and draws the background. mousepressed: Gets a new random value for each dice and calls drawdice for each one. Example: drawdice (d4, 500); //d4 is number of dots on dice and 500 is x location Since you know the x location of each dice, you can pass the exact location to drawdice. Add println so you can see the dice throws: println(d1 + " " + d2 + " " + d3 + " " + d4 + " " + d5); drawdice: Receives two parameters, dots and x draw: Does nothing, but keeps the program running. All dice will be drawn at the same y value. Your screen should be long and narrow with each dice equal-distant apart. drawdice will draw a dice based on the dots received. The location of the dice is based on the x received. Rubric Points Task trivial Setup Method 30 mousepressed Method 70 drawdice Method trivial draw 9

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

Pick 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 information

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

COMP 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 information

CISC 1600 Lecture 3.1 Introduction to Processing

CISC 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 information

Interaction Design A.A. 2017/2018

Interaction 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 information

1. Complete these exercises to practice creating user functions in small sketches.

1. 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 information

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

The 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 information

Basic Computer Programming (Processing)

Basic 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

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

COMP 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 information

[ the academy_of_code] Senior Beginners

[ 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 information

1 Getting started with Processing

1 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 information

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

Conditional 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 information

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

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca COMP 1010- Summer 2015 (A01) Jim (James) Young young@cs.umanitoba.ca jimyoung.ca order of operations with the explicit cast! int integervariable = (int)0.5*3.0; Casts happen first! the cast converts the

More information

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

Repetition 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 information

Exploring Processing

Exploring 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 information

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

We 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 information

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

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 information

Processing Assignment Write- Ups

Processing 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 information

CMPT-166: Sample Final Exam Answer Key

CMPT-166: Sample Final Exam Answer Key CMPT 166, Summer 2012, Surrey Sample Final Exam Answer Key Page 1 of 9 CMPT-166: Sample Final Exam Answer Key Last name exactly as it appears on your student card First name exactly as it appears on your

More information

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

+ 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 information

CST112 Looping Statements Page 1

CST112 Looping Statements Page 1 CST112 Looping Statements Page 1 1 2 3 4 5 Processing: Looping Statements CST112 Algorithms Procedure for solving problem: 1. Actions to be executed 2. Order in which actions are executed order of elements

More information

A B C D CS105 03a Interaction

A 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 information

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

Recall 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 information

CMPT-166: Sample Midterm

CMPT-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 information

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

Variables 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

Evaluating Logical Expressions

Evaluating 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

CISC 1600, Lab 2.1: Processing

CISC 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 information

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

What 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

Variables and Control Structures. CS 110 Eric Eaton

Variables 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 information

What 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 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 information

mith 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 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 information

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

Kimberly 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 information

If the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed.

If the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed. Conditionals 75 Reversing the Polarity of a Number When we want to reverse the polarity of a number, we mean that we want a positive number to become negative and a negative number to become positive.

More information

CSE120 Wi18 Final Review

CSE120 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 information

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

Variables. 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 information

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

What 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 information

Computer Graphics. Interaction

Computer 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 information

mith 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 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 information

Class #1. introduction, functions, variables, conditionals

Class #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 information

Appendix: Common Errors

Appendix: Common Errors Appendix: Common Errors Appendix 439 This appendix offers a brief overview of common errors that occur in Processing, what those errors mean and why they occur. The language of error messages can often

More information

Watch the following for more announcements

Watch 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 information

Chapter 5. Condi.onals

Chapter 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 information

The Processing language

The 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 information

CISC 1600, Lab 3.1: Processing

CISC 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 information

CS110 Introduction to Computing Fall 2016 Practice Exam 1 -- Solutions

CS110 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 information

CST112--Functions Page 1

CST112--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 information

Module 01 Processing Recap. CS 106 Winter 2018

Module 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 information

Introduction to Processing

Introduction to Processing Processing Introduction to Processing Processing is a programming environment that makes writing programs easier. It contains libraries and functions that make interacting with the program simple. The

More information

Final Exam Winter 2013

Final 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 information

Miscellaneous Stuff That Might Be Important.

Miscellaneous Stuff That Might Be Important. 1 Miscellaneous Stuff That Might Be Important. Variable mousepressed VS function mousepressed( ) For much of the work in this class, it is usually safer to use the function form of mousepressed( ) instead

More information

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:

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: 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 information

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

Using 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 information

Old 257 Exam #2s for Practice

Old 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 information

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

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values 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

More information

INTRODUCTION 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 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 information

Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor

Practice 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 information

GRAPHICS & INTERACTIVE PROGRAMMING. Lecture 1 Introduction to Processing

GRAPHICS & 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 information

Interaction Design A.A. 2017/2018

Interaction 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 information

Create a Swirly Lollipop Using the Spiral Tool Philip Christie on Jun 13th 2012 with 12 Comments

Create a Swirly Lollipop Using the Spiral Tool Philip Christie on Jun 13th 2012 with 12 Comments Advertise Here Create a Swirly Lollipop Using the Spiral Tool Philip Christie on Jun 13th 2012 with 12 Comments Tutorial Details Program: Adobe Illustrator CS5 Difficulty: Beginner Es timated Completion

More information

Arrays. Array an ordered collec3on of similar items. An array can be thought of as a type of container.

Arrays. Array an ordered collec3on of similar items. An array can be thought of as a type of container. Chapter 9 Arrays Arrays Array an ordered collec3on of similar items Student test scores Mail boxes at your college A collec3on of books on a shelf Pixels in an image the posi3ons for many stars in a night

More information

Shadows in the graphics pipeline

Shadows in the graphics pipeline Shadows in the graphics pipeline Steve Marschner Cornell University CS 569 Spring 2008, 19 February There are a number of visual cues that help let the viewer know about the 3D relationships between objects

More information

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

All 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 information

CST112 Variables Page 1

CST112 Variables Page 1 CST112 Variables Page 1 1 3 4 5 6 7 8 Processing: Variables, Declarations and Types CST112 The Integer Types A whole positive or negative number with no decimal positions May include a sign, e.g. 10, 125,

More information

Module 01 Processing Recap

Module 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 information

CPSC Fall L01 Final Exam

CPSC Fall L01 Final Exam CPSC 601.36 - Fall 2009 - L01 Final Exam Copyright Jeffrey Boyd 2009 December 12, 2009 Time: 120 minutes General instructions: 1. This exam is open-book. You may use any reference material you require,

More information

Light, Reflection and Mirrors. Light Reflection

Light, Reflection and Mirrors. Light Reflection Name: Light Reflection Read from Lesson 1 of the Reflection chapter at The Physics Classroom: http://www.physicsclassroom.com/class/refln/u13l1a.html http://www.physicsclassroom.com/class/refln/u13l1b.html

More information

PROGRAMMING. We create identity

PROGRAMMING. We create identity 2 PROGRAMMING We create identity TOPICS COVERED Getting Started Setup and draw Variables mousex, mousey other system variables variable declaration types Arithmetic Predefined methods abs, max, delay Topics

More information

Bits and Bytes. How do computers compute?

Bits 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 information

Simulation and User Interaction

Simulation 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 information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

CS Problem Solving and Object-Oriented Programming

CS Problem Solving and Object-Oriented Programming CS 101 - Problem Solving and Object-Oriented Programming Lab 5 - Draw a Penguin Due: October 28/29 Pre-lab Preparation Before coming to lab, you are expected to have: Read Bruce chapters 1-3 Introduction

More information

SFPL Reference Manual

SFPL 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 information

Name 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. 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 information

Chapter 2 Exercise Solutions

Chapter 2 Exercise Solutions Chapter 2 Exercise Solutions EX 2.1. EX 2.2. EX 2.3. EX 2.4. EX 2.5. Explain the following programming statement in terms of objects and the services they provide. System.out.println ("I gotta be me!");

More information

Unit O Student Success Sheet (SSS) Right Triangle Trigonometry (sections 4.3, 4.8)

Unit O Student Success Sheet (SSS) Right Triangle Trigonometry (sections 4.3, 4.8) Unit O Student Success Sheet (SSS) Right Triangle Trigonometry (sections 4.3, 4.8) Standards: Geom 19.0, Geom 20.0, Trig 7.0, Trig 8.0, Trig 12.0 Segerstrom High School -- Math Analysis Honors Name: Period:

More information

CSC 220 Object-Oriented Multimedia Programming, Spring 2017

CSC 220 Object-Oriented Multimedia Programming, Spring 2017 CSC 220 Object-Oriented Multimedia Programming, Spring 2017 Dr. Dale E. Parson, Assignment 2, Working with 3D shapes and geometric transforms. This assignment is due via D2L Dropbox Assignment 2 ShapePaint3DIntro

More information

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position } Review Commenting your code Random numbers and printing messages mousex, mousey void setup() & void draw() framerate(), loop(), noloop() Arcs, curves, bézier curves, beginshape/endshape Example Sketches

More information

Introduction to Processing. Sally Kong

Introduction 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 information

Module 05 User Interfaces. CS 106 Winter 2018

Module 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 information

CS110 Introduction to Computing Fall 2016 Practice Exam 1

CS110 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 information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation GRAPHICS PROGRAMMING LAB #3 Starting a Simple Vector Animation Introduction: In previous classes we have talked about the difference between vector and bitmap images and vector and bitmap animations. In

More information

Processing & Arduino in Tandem. Creating Your Own Digital Art Tools

Processing & 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 information

CISC 1600, Lab 2.2: Interactivity in Processing

CISC 1600, Lab 2.2: Interactivity in Processing CISC 1600, Lab 2.2: Interactivity in Processing Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad, a site for building processing sketches online using processing.js.

More information

5.1. Examples: Going beyond Sequence

5.1. Examples: Going beyond Sequence Chapter 5. Selection In Chapter 1 we saw that algorithms deploy sequence, selection and repetition statements in combination to specify computations. Since that time, however, the computations that we

More information

Preparation: Get to know the Java coordinate system. 3. How is the background color of the window specified? Copy the exact code:

Preparation: Get to know the Java coordinate system. 3. How is the background color of the window specified? Copy the exact code: Lab 9 Name: Checked: Objectives: Introduction to graphics and JavaFX. Preparation: Get to know the Java coordinate system Download Snowman.java. Compile and run it to see the image it produces. 1. Note

More information

University of Cincinnati. P5.JS: Getting Started. p5.js

University 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 information

Interaction Design A.A. 2017/2018

Interaction 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 information

Iteration in Programming

Iteration 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 information

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

COMP 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 information

Name 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. 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 information

Dice in Google SketchUp

Dice in Google SketchUp A die (the singular of dice) looks so simple. But if you want the holes placed exactly and consistently, you need to create some extra geometry to use as guides. Plus, using components for the holes is

More information

Methods (cont.) Chapter 7

Methods (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 information

Tools of Design Select Mode vs. Text Mode Select Mode allows you to alter the position and size of both text and clipart Text Mode allows you change text size, font and characters but you CANNOT

More information

Visual C# Program: Simple Game 3

Visual C# Program: Simple Game 3 C h a p t e r 6C Visual C# Program: Simple Game 3 In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Opening Visual C# Editor Beginning a

More information

CISC 1600, Lab 3.2: Interactivity in Processing

CISC 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 information

This document should only be used with the Apple Macintosh version of Splosh.

This document should only be used with the Apple Macintosh version of Splosh. Splosh 1 Introduction Splosh is an easy to use art package that runs under both Microsoft Windows and the Macintosh Mac OS Classic or Mac OS X operating systems. It should however be noted that the Apple

More information

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

Interactive Tourist Map

Interactive Tourist Map Adobe Edge Animate Tutorial Mouse Events Interactive Tourist Map Lesson 1 Set up your project This lesson aims to teach you how to: Import images Set up the stage Place and size images Draw shapes Make

More information

3. Area and perimeter.notebook November 13, All rectangles with area 12cm 2 have the same perimeter. True or false?

3. Area and perimeter.notebook November 13, All rectangles with area 12cm 2 have the same perimeter. True or false? All rectangles with area 12cm 2 have the same perimeter. True or false? Find the perimeter of the shape: Draw another shape with area a smaller perimeter. but with x y Write an expression for the perimeter

More information

Chapter 12: Functions Returning Booleans and Collision Detection

Chapter 12: Functions Returning Booleans and Collision Detection Processing Notes Chapter 12: Functions Returning Booleans and Collision Detection So far we have not done much with booleans explicitly. Again, a boolean is a variable or expression that takes on exactly

More information