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

Similar documents
Watch the following for more announcements

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Variables and Control Structures. CS 110 Eric Eaton

Chapter 2 Bits, Data Types, and Operations

Chapter 8. Characters and Strings

Chapter 2 Bits, Data Types, and Operations

Fundamentals of Programming (C)

Fundamentals of Programming

Chapter 2 Bits, Data Types, and Operations

Evaluating Logical Expressions

Chapter 2 Number System

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Data Representation and Binary Arithmetic. Lecture 2

Number Representations

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Chapter 2 Bits, Data Types, and Operations

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Oberon Data Types. Matteo Corti. December 5, 2001

The Binary Number System

ASSIGNMENT 5 TIPS AND TRICKS

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Chapter 2 Bits, Data Types, and Operations

Source coding and compression

+ Inheritance. n Superclass (base class) higher in the hierarchy. n Subclass (child class) lower in the hierarchy

Lecture (09) x86 programming 8

Variables and data types

Do not start the test until instructed to do so!

Chapter 3. Information Representation

Number System (Different Ways To Say How Many) Fall 2016

Do not start the test until instructed to do so!

Number Systems Base r

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Fundamental Data Types

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Midterm CSE 131 Winter 2013

CSE 30 Fall 2013 Final Exam

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

1 Getting started with Processing

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

CISC 1600, Lab 2.2: Interactivity in Processing

Midterm CSE 131 Fall 2014

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Midterm CSE 131 Winter 2012

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

CSE 30 Winter 2014 Final Exam

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

Do not start the test until instructed to do so!

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

CSE 30 Winter 2009 Final Exam

Exploring Processing

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

CS 159 Credit Exam. What advice do you have for students who have previously programmed in another language like JAVA or C++?

CSE 30 Fall 2012 Final Exam

Midterm CSE 131 Winter 2014

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

CISC 1600, Lab 3.2: Interactivity in Processing

Final CSE 131 Fall 2015

CST112 Variables Page 1

3.1. Unit 3. Binary Representation

Simple Data Types in C. Alan L. Cox

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

CSE 30 Spring 2006 Final Exam

CSE 30 Spring 2007 Final Exam

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Getting Started in Java CIS 110

Chapter 4: Basic C Operators

CSE 30 Fall 2007 Final Exam

Midterm CSE 131 Winter 2015

User s Manual. Xi3000 Scanner. Table of Contents

Digital Representation

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Final CSE 131 Winter 2010

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

A B C D CS105 03a Interaction

The following are the data types used in the C programming language:

FD-011WU. 2D Barcode Reader User Guide V1.6CC

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

CPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation

Miscellaneous Stuff That Might Be Important.

Computer Graphics. Interaction

Transcription:

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 Dropbox Assignment #1

vevents.pde

void mousepressed() { // Called when the mouse is pressed void mousereleased() { // Called when the mouse is released void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position void mousemoved() { // Called while the mouse is being moved // with the mouse button released void mousedragged() { // Called while the mouse is being moved // with the mouse button pressed

void keypressed() { // Called each time a key is pressed void keyreleased() { // Called each time a key is released void keytyped() { // Called when an alpha-numeric key is pressed // Called repeatedly if the key is held down

keycode vs. key key A built-in variable that holds the character that was just typed at the keyboard keycode A built-in variable that hold the numeric code for the keyboard key that was touched All built-in keyboard interaction functions set keycode to the integer that codes for the keyboard key set key to the character typed All keyboard keys have a keycode value Not all have a key value

ASCII - American Standard Code for Information Interchange Char Dec Char Dec Char Dec Char Dec Char Dec Char Dec Char Dec (nul) 0 (dc4) 20 ( 40 < 60 P 80 d 100 x 120 (soh) 1 (nak) 21 ) 41 = 61 Q 81 e 101 y 121 (stx) 2 (syn) 22 * 42 > 62 R 82 f 102 z 122 (etx) 3 (etb) 23 + 43? 63 S 83 g 103 { 123 (eot) 4 (can) 24, 44 @ 64 T 84 h 104 124 (enq) 5 (em) 25-45 A 65 U 85 i 105 125 (ack) 6 (sub) 26. 46 B 66 V 86 j 106 ~ 126 (bel) 7 (esc) 27 / 47 C 67 W 87 k 107 (del) 127 (bs) 8 (fs) 28 0 48 D 68 X 88 l 108 (ht) 9 (gs) 29 1 49 E 69 Y 89 m 109 (nl) 10 (rs) 30 2 50 F 70 Z 90 n 110 (vt) 11 (us) 31 3 51 G 71 [ 91 o 111 (np) 12 (sp) 32 4 52 H 72 \ 92 p 112 (cr) 13! 33 5 53 I 73 ] 93 q 113 (so) 14 " 34 6 54 J 74 ^ 94 r 114 (si) 15 # 35 7 55 K 75 _ 95 s 115 (dle) 16 $ 36 8 56 L 76 ` 96 t 116 (dc1) 17 % 37 9 57 M 77 a 97 u 117 (dc2) 18 & 38 : 58 N 78 b 98 v 118 (dc3) 19 ' 39 ; 59 O 79 c 99 w 119

More Color colormode(rgb or HSB); RGB: (red, green, blue) HSB: hue pure color saturation intensity brightness lightness

Decimal vs. Binary vs. Hexadecimal Decimal Hex Binary 0 00 00000000 1 01 00000001 2 02 00000010 3 03 00000011 4 04 00000100 5 05 00000101 6 06 00000110 7 07 00000111 8 08 00001000 9 09 00001001 10 0A 00001010 11 0B 00001011 12 0C 00001100 13 0D 00001101 14 0E 00001110 15 0F 00001111 16 10 00010000 17 11 00010001 18 12 00010010 counter.pde

Primitive Data Types Type Range Default Bytes boolean { true, false false? byte { 0..255 0 1 int { -2,147,483,648 0 4.. 2,147,483,647 long { -9,223,372,036,854,775,808 0 8.. 9,223,372,036,854,775,807 float { -3.40282347E+38 0.0 4.. 3.40282347E+38 double much larger/smaller 0.0 8 color { #00000000.. #FFFFFFFF black 4 char a single character 'a', 'b', '\u0000' 2 bits.pde / colorbits.pde

Variables A name to which data can be assigned A variable is declared as a specific data type A variable is assigned a value using '=' Variable names must begin with a letter, _ or $ Variables can container letters, digits, _ and $ Syntax: type name; type name = expression; int i; float x; int j = 12; boolean bready = true; float fsize = 10.0; color _red = color(255,0,0); Variables are both declared and assigned a value

Rewrite randomellipse using Variables void draw() { fill( random(255), random(255), random(255) ); ellipse(mousex, mousey, 30, 30); void draw() { float R, G, B; R = random(255); G = random(255); B = random(255); fill( R, G, B ); ellipse(mousex, mousey, 30, 30); void draw() { float R = random(255); float G = random(255); float B = random(255); fill( R, G, B ); ellipse(mousex, mousey, 30, 30);

Using Variables Draws a line from last mouse position to current. Variables used to store last mouse position. // Variables that store the last mouse pressed position. int lastx; // Note where these are declared! int lasty; void setup() { size(500, 300); void draw() { /* must exist */ // Draw a line from the last mouse position // to the current position. void mousepressed() { line(lastx, lasty, mousex, mousey); lastx = mousex; lasty = mousey; variables1.pde

Using Variables Orbit mouse with two shapes. Variables used for temporary calculated values. // Mouse orbiter float angle; // Orbit angle state variable void setup() { size(500, 300); background(255); void draw() { background(255); fill(0, 0, 255); angle = angle + 0.3; // Increment angle float dx = 30.0*cos(angle); // Mouse position offset float dy = 30.0*sin(angle); // Draw two orbiting shapes ellipse(mousex + dx, mousey + dy, 5, 5); ellipse(mousex - dx, mousey - dy, 5, 5); variables2.pde

Data Type Conversion Variables of some types can be converted to other types. Type conversion function names are the types to which data will be converted. // binary( ), boolean( ), byte( ), // char( ), float( ), str( ) float f = 10.5; int i; //i = f; i = int(f); println( char(65) ); // Throws a runtime error // Prints the character 'A'

Other "things" Type Range Default Bytes String a series of chars in quotes "abc" null? PImage an image null? PFont a font for rendering text null? String message = "Hello World!";

Images PImage img; Declares a variable to hold an image img = loadimage(filename); Loads an image from a file in the data folder in sketch folder. Must be assigned to a variable of type PImage. image(img, X, Y, [X2, Y2]); Draws the image img on the canvas at X, Y Optionally fits image into box X,Y and X2,Y2 imagemode(corner); X2 and Y2 define width and height. imagemode(corners); X2 and Y2 define opposite corner.

Image Example imageexample imageexample.pde data natura-morta.jpg PImage img; void setup() { size(500, 400); img = loadimage("natura-morta.jpg"); image(img, 50, 40); imageexample.pde

Expressions Series of data values, variables and/or subexpressions, related by operators and functions, and grouped by parentheses. Expressions are automatically evaluated and replaced by the final evaluated value. Expressions can be assigned to variables using = Expression is always on right Variable name is always on left variable_name = expression;

Operators Symbols that operate on one or two sub-expressions. Infix, prefix, or postfix Mathematical ( +, -, *, /, ) Perform standard mathematical operations (PEMDAS) Relational ( <, >, ==,!=, ) Test relationship between related expressions. Always returns a boolean value (true or false). Logical ( &&,,! ) Logical conjunction (and), disjunction (or), negation (not). Always returns a boolean value (true or false).

Mathematical Operators +, -, *, / and i ++; equivalent to i = i + 1; i += 2; equivalent to i = i + 2; i --; equivalent to i = i 1; i -= 3; equivalent to i = i - 3; i *= 2; equivalent to i = i * 2; i /= 4; equivalent to i = i / 4; i % 3; the remainder after i is divided by 3 (modulo) Examples: 1 + 2 slope = (y2 - y1) / (x2 x1); i++

Relational Operators < less than > is greater than <=is less than or equal to >=is greater than or equal to ==is equivalent!=is not equivalent Examples: true 10 >= 10 'A'!= 'A'

Logical Operators && logical conjunction (and) both expressions must evaluate to 'true' for conjunction to evaluate to 'true' logical disjunction (or) either expression must evaluate to 'true' for disjunction to evaluate to 'true'! logical negation (not)!true false,!false true Examples: true && true true false!false

Evaluating Logical Expressions Negation (!A ) A!A false true true false Conjunction "AND" (A && B) Disjunction "OR" (A B) A B A && B A B A B true true true true true true true false false true false true false true false false true true false false false false false false Derive new tables by combining operators 1. If I've already had two desserts, then don't serve me any more. Otherwise, I'll take another, thank you. A = had_dessert_1, B = had_dessert_2!(a && B) or!a!b A B!(A && B) true true false true false true false true true false false true 2. I'll have dessert, as long as it is not flan (A) or beef jerky (B).

Some Built-in Mathematical Functions sin(x), cos(x), tan(x), asin(x), abs(x), exp(x), pow(x, y), log(x), sqrt(x), max(x1, x2), min(x1, x2), floor(x), ceil(x), dist(x1, y1, x2, y2) -> distance between two points norm(value, low, high) -> normalizes a value to [0-1] and many more, all of which can be included in an expression.

Evaluating Expressions 1 + 2 pow(sin(x),2) + pow(cos(x),2) == 1.0 max(1, 2, 3) >= 2 floor(2.9) == ceil(1.8) void setup() { float r = 200.0; size( 500, 200+300 ); background( 0.5*r, 0, 0 );