A B C D CS105 03a Interaction

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

Computer Graphics. Interaction

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

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

Watch the following for more announcements

Exploring Processing

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

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Basic Input and Output

Basic Input and Output

Introduction to Processing. Sally Kong

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Interaction Design A.A. 2017/2018

Basic Computer Programming (Processing)

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

Basic Input and Output

CISC 1600, Lab 3.2: Interactivity in Processing

Basic Input and Output

The Processing language

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

CISC 1600, Lab 2.2: Interactivity in Processing

Bits and Bytes. How do computers compute?

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

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

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

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

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

INTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen

Introduction to Processing

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

(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

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

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

CMSC427 Interac/ve programs in Processing: Polyline editor

1 Getting started with Processing

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

Final Exam Winter 2013

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

Variables and Control Structures. CS 110 Eric Eaton

Getting Started in Java CIS 110

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

The Junior Woodchuck Manuel of Processing Programming for Android Devices

CS 101 Functions. Lecture 15

CST112 Variables Page 1

Interaction Design A.A. 2017/2018

CSE120 Wi18 Final Review

CS110 Introduction to Computing Fall 2016 Practice Exam 1

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

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

CISC 1600 Lecture 3.1 Introduction to Processing

Module 05 User Interfaces. CS 106 Winter 2018

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

Module 01 Processing Recap. CS 106 Winter 2018

CISC 1600, Lab 3.1: Processing

The Processing language. Arduino and Processing.

if / if else statements

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

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:

EP486 Microcontroller Applications

Class Notes CN19 Class PImage Page

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

Evaluating Logical Expressions

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

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

CISC 1600, Lab 2.1: Processing

Lecture 6: Processing

[ the academy_of_code] Senior Beginners

Processing Assignment Write- Ups

cs6964 March TOOLKITS Miriah Meyer University of Utah

GRAPHICS & INTERACTIVE PROGRAMMING. Lecture 1 Introduction to Processing

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

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

Solution Notes. COMP 151: Terms Test

Iteration in Programming

5.1. Examples: Going beyond Sequence

Chapter 5. Condi.onals

CS 106 Winter Lab 03: Input and Output

AP Computer Science Principles Python Programming Using Processing

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

1 Getting started with Processing

Module 01 Processing Recap

Methods (cont.) Chapter 7

CS 106A, Lecture 14 Events and Instance Variables

Art, Randomness, and Functions

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

Graphics with Processing

INDEX. Symbols. The SparkFun Guide to Processing: Create Interactive Art with Code! 2015 Derek Runberg 266 INDEX

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

Transform 1: Translate, Matrices

Braitenberg code. Page 1

Sten-SLATE ESP. Graphical Interface

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

Khan Academy JavaScript Study Guide

CS 106A, Lecture 14 Events and Instance Variables

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

Simulation and User Interaction

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

for(int i = 0; i < numbers.length; i++) {

Interaction Design A.A. 2017/2018

Miscellaneous Stuff That Might Be Important.

Transcription:

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); // purple A B C D CS105 03a Interaction 2

(demo) active mode CS105 03a Interaction 3 Functions Code that is packaged so it can be run by name Often performs some computation and returns a value (but not always) We use functions all the time in Processing nofill(); ellipse(75, 50, 23, 52); CS105 03a Interaction 4

Active Mode vs. Static Mode We have been writing code in static mode: - our drawing is only shown when the program finishes - there is no user input - we can t define any functions From now on, we re using active mode: - people can interact with our program - drawings can be updated to make animation - we can define functions - with setup() and draw() functions also called dynamic mode CS105 03a Interaction 5 Function Definition function return type function name function parameters code block CS105 03a Interaction 6

red_dot void setup() { mousex, mousey background in draw() CS105 03a Interaction 7 Static Mode Active Mode CS105 03a Interaction 8

(demos) mixing modes wrong function definitions CS105 03a Interaction 9 Trace of setup and draw see: 03a Interaction (trace).pdf CS105 03a Interaction 10

Sequential Control Flow runs 1st, runs once runs 2nd, runs continuously CS105 03a Interaction 11 (demo flow) println to trace program flow (using framecount, framerate too) void setup() { size(200, 200); framerate(1); // 1 frame per second println("setup"); background(230); // almost white fill(255, 0, 0); // red ellipse(mousex, mousey, 30, 30); println("draw frame " + framecount); CS105 03a Interaction 12

Which image is drawn by this code? void setup() { strokeweight(10); stroke(0, 255, 0); // green line(99, 0, 0, 99); stroke(200, 0, 200); // purple A B C D CS105 03a Interaction 13 CS105 03a Interaction 14 Event CREDIT: http://thenextweb.com/

Event CREDIT: http://wikimedia.org CS105 03a Interaction 15 Event CREDIT: http://www.opusa.org/ CS105 03a Interaction 16

Event 1. An observable occurrence, phenomenon, or an extraordinary occurrence. 2. A message to notify an application that something happened. Examples: Keyboard (key press, key release) Mouse Events (button press, button release, moved) CS105 03a Interaction 17 Setup and Draw are Events The setup event happens when the program is first run - setup() is a built-in function that represents this event - Processing calls setup() when the setup event occurs The draw event happens 60 times per second (by default) draw() is a built-in function that represents this event - Processing calls draw() when the draw event occurs We customize setup() and draw() function to do something when these events occur CS105 03a Interaction 18

Trace Through: setup() and draw() 1 2 3 4 5 6 7 8 9 // red dot void setup() { size(200, 200); nostroke(); fill(255, 0, 0); // red background(240); // almost white ellipse(mousex, mousey, 30, 30); CS105 03a Interaction 19 Trace Through: setup() and draw() 1 2 3 4 5 6 7 8 9 // red dot void setup() { size(200, 200); nostroke(); fill(255, 0, 0); // red background(240); // almost white ellipse(mousex, mousey, 30, 30); wait for 16ms CS105 03a Interaction 20

Trace Through: setup() and draw() 1 2 3 4 5 6 7 8 9 // red dot void setup() { size(200, 200); nostroke(); fill(255, 0, 0); // red background(240); // almost white ellipse(mousex, mousey, 30, 30); CS105 03a Interaction 21 mousepressed Event A mousepressed event happens when a mouse button is pressed (or a touch pad tapped) - mousepressed() is a built-in function that represents this event - Processing calls mousepressed() when the event occurs We customize the mousepressed() function to do something when this event occurs (there s also a mousereleased event) void mousepressed() { CS105 03a Interaction 22

keypressed Event A keypressed event happens when a key is pressed - keypressed() is a built-in function that represents this event - Processing calls keypressed() when the event occurs We customize the keypressed() function to do something when this event occurs (there s also a keyreleased even) void keypressed() { CS105 03a Interaction 23 paint keypressed() mousepressed() mousereleased(); CS105 03a Interaction 24

Which image is drawn by this code one second after the mouse button was pressed? rect(25, 25, 50, 50); void mousepressed() { fill(0); // black ellipse(50, 50, 25, 25); Nothing: the program crashes A B C D CS105 03a Interaction 25 Variables A symbolic name used to reference an unknown value. The value may change, but the symbolic name doesn t. Kinds of Variables - built-in variables (e.g. mousex, width) - constants (CENTER, BEVEL) - user defined variables CS105 03a Interaction 26

Useful Processing Built-in Variables mousex, mousey pmousex, pmousey width, height framecount, framerate displaywidth, displayheight key, keycode mousebutton keypressed, mousepressed (NOTE: different than the event functions with same names!) CS105 03a Interaction 27 (demos) background(255); line(mousex - 25, mousey - 25, mousex + 25, mousey + 25); background(255); line(width / 2, height / 2, mousex, mousey); CS105 03a Interaction 28

two using built-in variables in expressions exercises: move number up and down too extend demo to move other numbers CS105 03a Interaction 29