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

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

Bits and Bytes. How do computers compute?

Art, Randomness, and Functions

Chapter 5. Condi.onals

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

Final Exam Winter 2013

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

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

Basic Computer Programming (Processing)

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

A B C D CS105 03a Interaction

Basic Input and Output

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

1 Getting started with Processing

[ the academy_of_code] Senior Beginners

CISC 1600 Lecture 3.1 Introduction to Processing

Basic Input and Output

CISC 1600, Lab 2.1: Processing

Basic Input and Output

Class #1. introduction, functions, variables, conditionals

Basic Input and Output

CISC 1600, Lab 3.1: Processing

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

Exploring Processing

Interaction Design A.A. 2017/2018

Review Functions. Natural Language and Dialogue Systems Lab

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

CISC 1600, Lab 2.2: Interactivity in Processing

Design Programming DECO2011

Watch the following for more announcements

Introduction to Processing. Sally Kong

Processing Assignment Write- Ups

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

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

Interaction Design A.A. 2017/2018

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

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

CISC 1600, Lab 3.2: Interactivity in Processing

Ex: If you use a program to record sales, you will want to remember data:

1 Getting started with Processing

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

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

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

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

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

CS 101 Functions. Lecture 15

Name CMPS 5J Final March 17, 2010 This is a closed notes, closed book exam. Each problem is worth 1 point unless indicated otherwise.

5.1. Examples: Going beyond Sequence

ACTIVE PROCESSING Summary Learning Objectives How to Proceed Check your Understanding Learning Objectives 412

Variables and Control Structures. CS 110 Eric Eaton

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

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

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Review Web Search. Functions & Functional Abstraction & More Functions. Natural Language and Dialogue Systems Lab

The Processing language. Arduino and Processing.

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

Midterms Save the Dates!

if / if else statements

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

Interaction Design A.A. 2017/2018

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

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

The Processing language

Topic Notes: Java and Objectdraw Basics

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

Introduction to Processing

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CST112 Variables Page 1

Iteration in Programming

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

SCRATCH MODULE 3: NUMBER CONVERSIONS

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

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

An Introduction to Processing

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

Chapter 12: Functions Returning Booleans and Collision Detection

Activity 3: Data Types

COMP : Practical 8 ActionScript II: The If statement and Variables

Processing/Java Syntax. Classes, objects, arrays, and ArrayLists

Honors Computer Science Python Mr. Clausen Program 7A, 7B

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

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

Lesson 6 page 1. If you look at the bottom right of the Scratch color choices, you will see it say MORE BLOCKS in Purple.

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

2D Shapes. Creative Coding & Generative Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

Khan Academy JavaScript Study Guide

CMPT-166: Sample Midterm

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

Spring CS Homework 3 p. 1. CS Homework 3

Late Penalty: Late assignments will not be accepted.

Module 01 Processing Recap. CS 106 Winter 2018

Program Fundamentals

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

Standards/ Strands Essential Questions Skills Assessment. What are the strengths and weaknesses of Processing as a programming language?

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

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Appendix: Common Errors

Sten-SLATE ESP. Graphical Interface

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Transcription:

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 s check. Illustrate A Way To Do It The Plan hide subversive protest picture in calendar art Host Image Guest Image 2/5/13 2011 Larry Snyder, CSE 3 Step 2: Replace Bits In Host Remember how colors work What bits matter most? Put guest bits into right 2 bits of host Pure red is 255 255 15 => 240 11111111 00001111= 11110000 128 + 64 = 192 10000000 + 01000000 = 11000000 If you had to throw away some bits from each pixel of a message which should you throw away so that the remaining image was a close to the original as possible? A. The rightmost (low order bits). B. The leftmost (high order bits). C. Doesn t matter, just how many you throw is all that matters. 1111 0100 1101 0011 1011 1101 1011 0100 1101 0011 0001 1100 1111 0110 1101 0011 1011 1100 2/5/13 2011 Larry Snyder, CSE 4 1

What Does the Multiplication *, Mod % Do? MOD operator % Processing_review_whatisthismodfn Multiplication operator. Show_mod_mult_onscreen Read in the file, and then on mouse click, pull out the bits and make a picture int count = 0; size(120,120); textsize(64); textalign(center); framerate(2); Remove right 2 bits background(0); //(count % 4 == 0) //(count % 2 == 0) Make them left 2 bits for each color New color //(count % 6 == 0) if (count % 3 == 0) { //println(count); text(count,60,80); count = count + 1; 2/5/13 2011 Larry Snyder, CSE 7 Homework 7 Making Blinky Work Data types Primitive data types int: numbers without a decimal point. boolean: data type for the boolean values true or false. color: storing color values Function color(r, G, B); creates a color that can be stored in variable of the color data type Sample Code: HW 7 answer part 1: A flag is a way to tell you whether you should go this way or that way in your program. (Combines with if-else, is either TRUE or FALSE (1 or 0)) 2

The if statement if - else Relational Operators if (BooleanExpression) Statement true Statement BooleanExpr false Expression (test) - true or false (boolean). Statements executable: call a function, assign a value, etc. if: expression inside the parentheses is true, execute the statements enclosed within the curly brackets. else: extends the if() structure, when the expression in if() is false, execute the statements enclosed within the curly brackets. Sample syntax: Returns a boolean value (true/false) Return true/false expressions (or boolean values) Sample Code: == (equality) > (greater than) >= (greater than or equal to)!= (inequality) < (less than) <= (less than or equal to) Logical Operators HW 7 answer part 2 This can work too (notice the else if ): Connect two or more true/ false expressions (or boolean values) Sample code using && : Change the moving and looking direction of Blinky This will not work, Blinky will not move right: && (logical AND)! (logical NOT) (logical OR) Sample code using : Mouse to the right of blinky Mouse in the middle of blinky HERE! BUG! Sample code using! : Mouse to the left of blinky Can you figure Change direction out why? NATURAL LANGUAGE AND DIALOGUE and look SYSTEMS LAB 3

mousex, mousepressed() HW 7 answer part 3: We can find out the color through the variable colorflag mousex: this system variable always contains the current horizontal coordinate of the mouse mousey: this system variable always contains the current VERTICAL coordinate of the mouse mousepressed(): this function is called automatically by the system once after every time a mouse button is pressed. Sample syntax: If I m marked as red Change me to yellow Mark me as yellow If I m not marked as red, then I must be yellow Change me to red Mark me as red Processing Review: What you should have seen so far. Kinds of multiple choice questions that might be on midterm What is a variable? Variables Processing review ellipse click 1 a named location in the computers memory mousex mousey width height fontcolor username store/remember values can be changed must be declared to store a particular kind of value (e.g. whole number, fraction, character, color, image, boolean) should have a descriptive name (so you know what it does or is supposed to do) start with letter can also include numbers no spaces size(500,500); int diameter = 0; ellipse(width/2, height/2, diameter,diameter); diameter = diameter + 5; What does this display? A) many nested circles (like a target) growing in size B) a white circle growing in size C) a black circle growing in size D) a pulsing images of circles growing and shrinking E) nothing (a circle with diameter 0) 4

primitive types (Java) declaring vs. initializing vs. assigning Processing review click 2 boolean - true or false char - a, b, c, byte - small integer -128 to 127 short - bigger integer -32768 to 32767 int - even bigger integer +/- 2 billion long - really big integer float - numbers with fractional parts 3.1415 double - like float but more precision int carfront; // declare int carfront = 100; // declare and initialize carfront = carfront - 1; // assign size(200, 200); background(255); int xpos = 0; ellipse(xpos, height/2, 20, 20); xpos = xpos + 1; What does this draw? A) circle moving across the screen left to right B) circle moving across the screen right to left C) circle moving across the screen top to bottom D) circle moving across the screen bottom to top E) half-circle on the left edge not moving System Variables (Processing) mousex, mousey pmousex, pmousey width, height framecount Processing Review placement click 3 size(400, 400); fill(255-abs(mousex-pmousex)); rect(pmousex, pmousey, mousex, mousey); size(400, 400); // position A // position B // position C fill(255-abs(mousex-pmousex)); rect(pmousex, pmousey, mousex, mousey); // position D Where should the line background(255); be placed so that the sketch shows just a single moving rectangle? Choose option E if it would work with either C or D. 5

Making Choices If you wish to defrost, press the defrost button; otherwise press the full power button. Let the dough rise in a warm place until it has doubled in size. If the ball reaches the side of the display change it s direction. Boolean Expressions Any expression that evaluates to true or false. Relational operators, <, <=, >, >=. Equality operators, ==,!=. For example: int i = 3, j = 4; 5 < 6 i == j (j + 2) <= 6 Expressions and Statements Expression statements are formed by adding a semicolon to the end of certain types of expressions. An assignment expression is an expression involving an assignment. area = width * height; A method call expression has no assignment. rect( ); Non-statements Blocks The if statement Not all expressions can be turned into statements. The following are syntax errors. x+y; width > 20; The above do not make sense as statements. They don t DO anything. Statements must DO something. assign a new value to a variable cause some output to occur (println(), rect()) change some internal state background(255); nostroke(); Several statements can be grouped into a block using {. { int x = 20, y = 30, size = 40; ellipsemode(corner); fill(255, 0, 0); rect(x, y, size, size); fill(0, 255, 0); ellipse(x, y, size, size); // x, y, and size above cannot be used // here if (BooleanExpression) Statement true Statement BooleanExpr false 6

MOD operator % Processing_review_whatisthismodfn int count = 0; size(120,120); textsize(64); textalign(center); framerate(2); background(0); //(count % 4 == 0) //(count % 2 == 0) //(count % 6 == 0) if (count % 3 == 0) { //println(count); text(count,60,80); count = count + 1; Processing_review_mod_frame_click_4 int count = 0; framerate(2); background(120); int x=20, y=30, size=40; if (count % 2 == 0) { ellipsemode(corner); fill(255, 0, 0); rect(x, y, size, size); fill(0, 255, 0); ellipse(x, y, size, size); count = count + 1; What is the effect of the ifclause? A. The drawing only happens every other frame. B. The drawing gets bigger and smaller depending on the current value of count. C. The background changes color when count % 2 equals 0 D. Nothing. The value of count keeps getting set to 0 every frame. Processing_review_ball_click5 int ballx, balldia = 50; size(400,400); ballx = -balldia/2; background(120); if (ballx > width+balldia/ 2) ballx = -balldia/2; ellipse(ballx, height/2, balldia, balldia); ballx = ballx + 1; A. Ball moves across jumping back to left edge as soon as it touches the right edge. B. Ball moves across moving off the right edge then moves back in from the left edge. C. Ball moves across until half way off the right edge (showing just a half circle) then reappears as a half circle on the left edge. D. Ball moves across then disappears and doesn t come back. E. Ball moves left to right then right to left after reaching the right edge, and repeats. The if-else statement Processing_review_ifcornerelse Processing (will do some more on Thurs) if (BooleanExpression) Statement1 else Statement2 true Statement1 BooleanExpr false Statement2 int count=0; size(500,500); framerate(2); //framerate(10); background(120); int x = 20, y = 30, size = 40; ellipsemode(corner); if (count % 2 == 0) { fill(255, 0, 0); rect(x, y, size, size); fill(0, 255, 0); ellipse(x, y, size, size); else { fill(0, 255, 0); rect(x, y, size, size); fill(255, 0, 0); ellipse(x, y, size, size); count = count + 1; What happens as count changes value? A. The color of the ellipse changes B. The color of the corners change C. Both the ellipse and the corner change color D. The rectangle with the ellipse blinks E. All of the above Drawing shapes Colors and their representations Conditional statements Values of variables Assignment, declaration 7

Announcements HW9: Creativity in Processing What can we do with Processing we haven t done yet? Creativity in Processing Due the week after the midterm. Will need to start right after the midterm. Get a programming partner! Go Crazy! https://courses.soe.ucsc.edu/courses/cmps10/winter13/01/ pages/syllabus Thursday : Review for Midterm (a week from today on Feb 12 th!!) Why Pair Programming? Having a partner gives you a built-in helper Many people find computers more fun if they get to work with someone else Learning to work with computers is like learning a foreign language, lots of new words and codes => Easier to learn a language if you have some to converse with in the language Working with a partner helps you develop good teamwork skills Most programming projects in real life done in teams Employers look for people who are good at teamwork A creativity program from last year Sierpinski: function call when mouse pressed 8

Processing Basics: Recursive Circles But is it art? Mondrian, Pollack, Albers are stars If (level > 1) If (level > 3) Ideas? More Pictures! 2/5/13 2010 Larry Snyder, CSE 51 Art In A Click Computer art, that is, art generated by computers, not art created by people using computers, leads to some fun Web sites.. Google piet mondrian. He was a cubist and created pictures that look like this http://www.google.com/search? client=safari&rls=en&q="piet +Mondrian"&ie=UTF-8&oe=UTF-8 Could we generate this in processing? How about something a little easier first? http://en.wikipedia.org/ wiki/josef_albers What would we do in Processing? What does Random do? 9

Random Numbers Random numbers should be called random number sequences, because the definition requires that no matter how many numbers you already know in the sequence, it s not possible to predict the next one. A non-random sequence is 2, 4, 6, 8, 10, Computers cannot produce random numbers (because computers are completely predictable), but they can produce a sequence of numbers that passes all of the tests for randomness. These are called pseudo-random numbers, but everyone drops the pseudo part. To generate a random number in Processing we write: random(<smallest possible number>, <largest possible number>). We get back a number we can t predict which between the two limits, including the end points. To generate a random number between 0 and 255, write random(0, 255). To generate a number between 0 and 1, write random(0, 1). Let s Try it! How about something a little easier first? http://en.wikipedia.org/ wiki/josef_albers How about Jackson Pollock? Computer generated Jackson Pollock? lerpcolor() Google jackson pollock. http://www.google.com/search?source=ig&hl=en&rlz=&q=jackson +pollock&btng=google+search He was an abstract expressionist and created paintings that look like this! Circa 1950 I made this on this website. http://www.jacksonpollock.org. There is a very interesting function called lerpcolor( ). It uses a mathematical idea (that we don t need to know about) called linear interpolation to pick intermediate colors. Give it two colors, say gold and purple, and it finds a color in between. Where in between? We also give it a fraction (.33,.66) between 0 and 1 that tells. Program fills in the black region in the middle with two colors between gold and purple. gold near_gold near_purple purple 10

POINTILISM Transparency, Tints and More! http://www.processing.org/learning/pixels/ http://www.processing.org/learning/pixels/ 11