Basic Computer Programming (Processing)

Size: px
Start display at page:

Download "Basic Computer Programming (Processing)"

Transcription

1 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 Function (Page 12) 9. Conditionals (Page 13) 10. Relational Operators (Page 14) 11. Logical Operators (Page 14) 12. Looping (Page 16) 13. Functions (Page 17) Page 1 of 19

2 Basic Concepts A computer program is a sequence of instructions, written to perform a specified task. Programmers are people who write the programs. Programming language is a computer language used to create programs. Different programming languages have their own sets of rules called syntax. A program is wrong if syntax errors are found. Source code of a program refers to the human-readable text written with a suitable computer language. Source code is often transformed into lower-level machine code understood by the computer. Executable file contains the machine code and it be executed on a suitable platform. Usually, execute file has an exe file extension. What is the meaning of open-source? What is the advantage of it? Processing Processing is a programming language initially created to teach computer programming fundamentals. Processing can be found in Download and extract it. Page 2 of 19

3 Open the folder and execute the processing.exe program. Remarks: Alternatively, you can download the program and the source codes of all examples in Page 3 of 19

4 Activity 1 1. Open Processing. 2. Type the following: ellipse (50, 50, 80, 80); 3. Click the RUN button. What is the output of the program? 4. Save the program. Name it as Activity1. Hence, a new folder is created. 5. Close Processing. 6. Open the Activity1 folder and open the file Activity1.pde. 7. Click File Export Application. 8. Choose the Windows platform. 9. Open the folder application.windows32 inside the Activity1 folder and find the file Activity1.exe. What is the name of source code file? What is the name of the executable file? Page 4 of 19

5 In the above program, ellipse is a function with 4 arguments inside the brackets. ellipse (a, b, c, d) a: x-coordinate of the ellipse b: y-coordinate of the ellipse c: width of the ellipse d: height of the ellipse Try to modify the values of the four arguments and observe the output of the program. Where is the origin of the coordinate system? Activity 2 Study the following functions. size (w, h) w: width of the display window h: height of the display window point (x, y) x: x-coordinate of the point y: y-coordinate of the line (x1, y1, x2, y2) x1: x-coordinate of the first point y1: y-coordinate of the first point x2: x-coordinate of the second point y2: y-coordinate of the second point triangle (x1, y1, x2, y2, x3, y3) quad (x1, y1, x2, y2, x3, y3, x4, y4) rect (a, b, c, d) a: x-coordinate of the rectangle b: y-coordinate of the rectangle c: width of the rectangle d: height of the rectangle Write a program to output the following. Page 5 of 19

6 Activity 3 Visit and learn three more functions: background, stroke and fill. Design a colourful logo. Statements and Comments Statements are the elements that make up programs. The ";" (semi-colon) symbol is used to end statements. Comments are used for making notes to help people better understand programs. A comment begins with two forward slashes ("//"). Example 1 // The size function is a statement that tells the computer how large to make the window. size (640, 360); // The background function is a statement that tells the computer // which color (or gray value) to make the background of the display window background (204, 153, 0); Page 6 of 19

7 Variables Variables are used for storing values. The values of the variables can be changed in the program. No space is allowed in the variable name. Example 2 size (400, 400); line (30, 40, 30, 340); line (30, 190, 130, 190); line (130, 40, 130, 340); //First stroke // Horizontal stroke // Last stroke The coordinates of the upper L.H.S. corner of the letter H are (30, 40), the width is 100 and the height is 300. It is tedious to change the position of the letter H in the program as we have to change many numbers in the program. In the following program, two variables are used to represent the coordinates of the upper L.H.S. corner and it is easier to change the position of the letter H. Example 3 size (400, 400); int x = 30; // x-coordinate of the upper L.H.S. corner int y = 40; // y-coordinate of the upper L.H.S. corner line (x, y, x, y + 300); line (x, y + 150, x + 100, y + 150); line (x + 100, y, x + 100, y + 300); Activity 4 Add two more variables in the last program such that you can easily control the height and the width of the letter H. Try to modify the values of the variables to produce the letter H with different sizes and positions. Page 7 of 19

8 Setup and Draw The code inside setup () runs once when the program is started. The code inside the draw () function runs continuously from top to bottom until the program is stopped. Example4 int x = 0; // Initial x-coordinate int y = 0; // Initial y-coordinate void setup () { size (400, 300); background (0, 255, 0); framerate (10); // Green colour background // 10 frames per second void draw () { x = x + 1; y = y + 1; point (x, y); // Increase the value of x-coordinate // Increase the value of y-coordinate // Draw a point Activity 5 Design a program to show a point initially at the center of the window. The point become a circle and the size is increasing. (Hint: The center of the window is (width / 2, height / 2).) Page 8 of 19

9 Data Types Different data types can be used to store different kinds of data. Data Type Description Example int Integer. int a = 4; float A number with decimal place. float b = 5.2; boolean A Boolean variable has only two boolean pass = true; possible values: true or false. char String A single character. A pair of single quotes is used to specify the value of the variable. A sequence of characters. S must be capitalized. A pair of double quotes is used to specify the value of the variable. Example 5 size (200, 100); char letter = 'A'; String words = "Hello Friends!"; background(0); // Set background to black textsize (14); text (letter, 20, 30); text (words, 20, 70); Activity 6 Complete the followings. Variable Data Type 1. Age 2. Name 3. Sex 4. Class 5. Average_mark 6. Married Page 9 of 19

10 Mouse Functions The coordinates of the previous mouse pointer are stored in the variables pmousex and pmousey. The coordinates of the current mouse pointer are stored in the variables mousex and mousey. The mouseclicked() function is called once every time a mouse is clicked. Example 6 void setup () { size (400, 400); void draw () { line (pmousex, pmousey, mousex, mousey); void mouseclicked () { background (200); Activity 7 In Example 6, the mouse is working like a pen to draw the line. Modify the program such that you can toggle the pen up and pen down status with a mouse click. (Hint: Declare a variable to represent the pen status.) Activity 8 Visit and learn more mouse functions such as mousepressed, mousedragged and mousebutton. Design a program with the following features. 1. Drag the mouse to draw rectangles with different sizes. 2. Click the right mouse button to clear the drawing. Page 10 of 19

11 Part of the program is given below. int oldx; // x-coordinate of the upper L.H.S. corner of the rectangle int oldy; // y-coordinate of the upper L.H.S. corner of the rectangle void setup () { size (400, 400); void draw () { void mousepressed () { if (mousebutton == RIGHT) background (200); // Clear the drawing oldx = ; oldy = ; void mousedragged () { rect (,,, ); Modify the above program such that a new colour is randomly assigned to a new rectangle. (Hint: Study the fill and random function on the Reference page.) Page 11 of 19

12 Keyboard Function The keypressed() function is called once every time a key is pressed. The key that was pressed is stored in the key variable. The data type of key is char. Example 7 int x = 200; // Initial x-coordinate int y = 150; // Initial y-coordinate void setup() { size (400, 300); void draw() { // keep draw() here to continue looping while waiting for keys void keypressed() { if (key=='6') x = x + 1; // Moving right if (key=='4') x = x - 1; // Moving left if (key=='8') y = y - 1; // Moving up if (key=='2') y = y + 1; // Moving down point (x, y); // Draw a point Example 8 int x = 200; // Initial x-coordinate int y = 150; // Initial y-coordinate void setup() { size (400, 300); void draw() { if (key=='6') x = x + 1; // Moving right if (key=='4') x = x - 1; // Moving left if (key=='8') y = y - 1; // Moving up if (key=='2') y = y + 1; // Moving down point (x, y); // Draw a point Run the two above programs. What is the difference between them? Page 12 of 19

13 Conditionals Conditional control structures allow a program to decide to take one action if the condition is true or to do another action if the condition is false. The conditions are always logical or relational statements. Control Syntax Structure if if (test) { statements Description Allows the program to make a decision about which code to execute. If the test evaluates to true, the statements enclosed within the block are executed and if the test evaluates to false the statements are not executed. if..else if (expression) { statements else { statements if..else if (expression_1) { statements_1 else if (expression_2) { Statements_2 else { Statements_3 Extends the if structure allowing the program to choose between two blocks of code. If the expression is true, the first block of statements is executed. Otherwise, the second block of statements is executed. expression_1 expression_2 Block of code will be executed true any value statements_1 false true statements_2 false statements_3 Activity 9 Modify the program in Example 7 such that you can control the movement of the point in 8 directions using the keys on the NumPad. Page 13 of 19

14 Relational Operators Operator Meaning < Less than > Greater than == Equality!= Inequality <= Less than or equal to >= Greater than or equal to Logical Operators In the following truth tables, there are two logical expressions P and Q. Logical expressions can hold two possible values only: true or false. && (and) P Q P && Q true true true true false false false true false false false false (or) P Q P Q true true true true false true false true true false false false! (not) P true false! P false true Example 10 Read the example carefully and decide which logical operator can check whether the marks are valid (i.e., between 0 and 100 inclusively). Page 14 of 19

15 Activity 10 Modify the program in Activity 9 such that the point will come back from the opposite side of the window when it leave the window at one side. Activity 11 Design a program to display a black square in one of the four quadrants according to the mouse location as below. Let s first write the logic of the program in pseudocode (i.e., English). Setup: 1. Set up a window of 200 x 200 pixels. Draw: 1. Draw a white background. 2. Draw horizontal and vertical lines to divide the window in four quadrants. 3. If the mouse is in the top left corner, draw a black square in the top left corner. 4. If the mouse is in the top right corner, draw a black square in the top right corner. 5. If the mouse is in the bottom left corner, draw a black square in the bottom left corner. 6. If the mouse is in the bottom right corner, draw a black square in the bottom right corner. Page 15 of 19

16 Looping Looping is a generative process of repeating a set of rules or steps over and over again. FOR Loop A for loop can have its own variable just for the purpose of controlling the number of loops. Example 11 size (200, 200); for (int i = 40; i <= 160; i=i+20) line (i, 10, i, 80); Here are the properties of the variable i in the for loop. Initial value: 40 The loop will continue if i <= 160 The value of i is increased by 20 in each loop. Activity 12 Draw 10 concentric circles with different radii. (Hint: Draw the larger circles first.) Try to use different colours in the circles. WHILE Loop Just as with conditional (if else) structures, a while loop employs a Boolean test condition. If the test evaluates to true, the instructions enclosed in curly brackets are executed; if it is false, we continue on to the next line of code. Syntax: while (Boolean test) { statements Example 12 int i = 0; while (i <= 100) { line (i, 100, i, i); i += 2; Remarks: i += 2; is the same as i = i + 2; Similarly, i++; i+=1; and i = i + 1; are different ways to increase the value of i by one. Page 16 of 19

17 Activity 13 Use a while to draw the following diagram. The length of the longest line is 100 units and the length of the shortest line is 10 units. In each loop, the length is decreased by 10 units. Functions In long programs, there are hundreds, thousands and even more lines of code. Functions are a means of taking the parts of long program and separating them into modular pieces, making the code easier to read, as well as to revise. A function definition (sometimes referred to as a declaration ) has three parts. 1. Return type 2. Function name 3. Parameters Example 13 void setup () { println (average (4, 5)); println (average (7, 8)); float average (int a, int b) { return ((a + b) / 2.0); The average function takes two integer parameters (a and b) and returns a float (non-integer) result. When calling the average function, two integer arguments should be provided. Page 17 of 19

18 Example 14 Suppose we are going to design a Space Invaders game. Out steps for draw () might look something like. 1. Draw background 2. Draw spaceship 3. Draw enemy 4. Move spaceship according to user keyboard interaction 5. Move enemy float shipx = 150; float shipy = 250; float EnemyX = 100; float EnemyY = 50; void setup () { size (300, 300); framerate (30); void draw () { background (); drawship (shipx,shipy); drawenemy (EnemyX, EnemyY); moveship (); moveenemy (); void background () { background (0); stroke (255); for (int i = 0; i < 10; i++) point (random (300), random (300)); void drawship (int x, int y) { stroke (0, 0, 255); fill (0, 255, 0); triangle (x, y, x - 20, y + 10, x + 20, y + 10); ellipse (x, y, 10, 40); void drawenemy (float x, float y) { void moveship () { if (key == CODED) { if (keycode == LEFT) shipx--; if (keycode == RIGHT) shipx++; if (keycode == UP) shipy--; if (keycode == DOWN) shipy++; void moveenemy () { Activity 14 Try to complete the above program. The enemy tries to catch the space ship. Page 18 of 19

19 Assignment Title Ping-pong game Task The following picture shows a very old game. Human player can control the movement of one racket to hit the ball. Another racket is controlled by the computer. You can enhance the game such as making the display more beautiful showing the scores determining the winner according to some defined rules more Requirements Submit a zip file to eclass with the following elements. 1. A Word document containing the descriptions and screenshots to show all the features of the game. 2. The source code of the program. Page 19 of 19

[ 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

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

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

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

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

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

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

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

1 Getting started with Processing

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

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

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

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

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

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

+ 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

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 Input and Output

Basic 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 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

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

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

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

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

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

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

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

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

Basic Input and Output

Basic Input and Output Basic Input and Output CSE 120 Winter 2019 Instructor: Teaching Assistants: Justin Hsia Ann Shan, Eunia Lee, Pei Lee Yap, Sam Wolfson, Travis McGaha Facebook to integrate WhatsApp, Instagram and Messenger

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

Basic Input and Output

Basic Input and Output Basic Input and Output CSE 120 Winter 2018 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Cheng Ni, Eugene Oh, Sam Wolfson, Sophie Tian, Teagan Horkan How the Facebook algorithm update will

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

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

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

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

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

An Introduction to Processing

An 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 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

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

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

Basic Input and Output

Basic Input and Output Basic Input and Output CSE 120 Spring 2017 Instructor: Justin Hsia Teaching Assistants: Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee How airlines like United choose who to kick off a flight On Sunday

More information

if / if else statements

if / 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 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

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

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

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

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

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

Lesson Two. Everything You Need to Know. 4 Variables 5 Conditionals 6 Loops

Lesson Two. Everything You Need to Know. 4 Variables 5 Conditionals 6 Loops Lesson Two Everything You Need to Know 4 Variables 5 Conditionals 6 Loops This page intentionally left blank 4 Variables Variables 45 All of the books in the world contain no more information than is broadcast

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

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

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

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

Khan Academy JavaScript Study Guide

Khan Academy JavaScript Study Guide Khan Academy JavaScript Study Guide Contents 1. Canvas graphics commands with processing.js 2. Coloring 3. Variables data types, assignments, increments 4. Animation with draw loop 5. Math expressions

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

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

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

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

CS 106 Winter Lab 03: Input and Output

CS 106 Winter Lab 03: Input and Output CS 106 Winter 2019 Lab 03: Input and Output Due: Wednesday, January 23th, 11:59pm Summary This lab will allow you to practice input and output. Each question is on a separate page. SAVE each sketch as

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

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

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM Introduction to the Assignment In this assignment, you will get practice with recursion. There are three parts

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

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

This assignment was revised from the original PDF released to revise/add Parts D and E.

This assignment was revised from the original PDF released to revise/add Parts D and E. Behind the Digital Screen Assignment 5: Visualization Deadline: Monday, 4/11, 3pm (one hour before class begins) This assignment was revised from the original PDF released to revise/add Parts D and E.

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

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

Computer and Programming: Lab 1

Computer and Programming: Lab 1 01204111 Computer and Programming: Lab 1 Name ID Section Goals To get familiar with Wing IDE and learn common mistakes with programming in Python To practice using Python interactively through Python Shell

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

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

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

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

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

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

CS 106 Winter Lab 05: User Interfaces

CS 106 Winter Lab 05: User Interfaces CS 106 Winter 2018 Lab 05: User Interfaces Due: Wednesday, February 6th, 11:59pm This lab will allow you to practice User Interfaces using Direct Manipulation and ControlP5. Each question is on a separate

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

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

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

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

Sten-SLATE ESP. Graphical Interface

Sten-SLATE ESP. Graphical Interface Sten-SLATE ESP Graphical Interface Stensat Group LLC, Copyright 2016 1 References www.arduino.cc http://esp8266.github.io/arduino/versions/2.1.0/doc/reference.html 2 Graphical Interface In this section,

More information

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)

ASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59) ASSIGNMENT 2 COMP-202A, Fall 2013, All Sections Due: October 20 th, 2013 (23:59) Please read the entire PDF before starting. You must do this assignment individually and, unless otherwise specified, you

More information

Design Programming DECO2011

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

Notes from the Boards Set BN19 Page

Notes from the Boards Set BN19 Page 1 The Class, String There are five programs in the class code folder Set17. The first one, String1 is discussed below. The folder StringInput shows simple string input from the keyboard. Processing is

More information

THE JAVASCRIPT ARTIST 15/10/2016

THE JAVASCRIPT ARTIST 15/10/2016 THE JAVASCRIPT ARTIST 15/10/2016 Objectives Learn how to program with JavaScript in a fun way! Understand the basic blocks of what makes a program. Make you confident to explore more complex features of

More information

Connecting Arduino to Processing

Connecting Arduino to Processing Connecting Arduino to Processing Introduction to Processing So, you ve blinked some LEDs with Arduino, and maybe you ve even drawn some pretty pictures with Processing - what s next? At this point you

More information

Solution Notes. COMP 151: Terms Test

Solution Notes. COMP 151: Terms Test Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms

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

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.

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

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING AN INTRODUCTION TO SCRATCH (2) PROGRAMMING Document Version 2 (04/10/2014) INTRODUCTION SCRATCH is a visual programming environment and language. It was launched by the MIT Media Lab in 2007 in an effort

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

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

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

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Mirage Language Reference Manual Image drawn using Mirage 1.1 Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Prof. Stephen Edwards Team Members: Abhilash I ai2160@columbia.edu

More information

Your First Windows Form

Your First Windows Form Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

More information

In this chapter: What is an array? Declaring an array. Initialization. Array operations using the for loop with an array. Arrays of objects.

In this chapter: What is an array? Declaring an array. Initialization. Array operations using the for loop with an array. Arrays of objects. 9 Arrays Arrays 141 I might repeat to myself slowly and soothingly, a list of quotations beautiful from minds profound if I can remember any of the damn things. Dorothy Parker In this chapter: What is

More information

CS 251 Intermediate Programming Java Basics

CS 251 Intermediate Programming Java Basics CS 251 Intermediate Programming Java Basics Brooke Chenoweth University of New Mexico Spring 2018 Prerequisites These are the topics that I assume that you have already seen: Variables Boolean expressions

More information