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

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

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

Bits and Bytes. How do computers compute?

Final Exam Winter 2013

Chapter 5. Condi.onals

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

A B C D CS105 03a Interaction

CISC 1600 Lecture 3.1 Introduction to Processing

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

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

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

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

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

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

Basic Computer Programming (Processing)

CISC 1600, Lab 3.1: Processing

Write a program that draws this image. The ligle squares are 5x5. The screen is the default 100x100. It doesn t change.

CISC 1600, Lab 2.1: Processing

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

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

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

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

Basic Input and Output

Introduction to Processing. Sally Kong

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

The Processing language

Basic Input and Output

CS 101 Functions. Lecture 15

1 Getting started with Processing

Interaction Design A.A. 2017/2018

Exploring Processing

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

CSE120 Wi18 Final Review

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

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

Design Programming DECO2011

Kimberly Nguyen Professor Oliehoek Introduction to Programming 8 September 2013

CMPT-166: Sample Midterm

Interaction Design A.A. 2017/2018

Basic Input and Output

Basic Input and Output

(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

CISC 1600, Lab 2.2: Interactivity in Processing

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:

Watch the following for more announcements

Art, Randomness, and Functions

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

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

CS110 Introduction to Computing Fall 2016 Practice Exam 1

Interaction Design A.A. 2017/2018

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

Class #1. introduction, functions, variables, conditionals

Using Methods. Writing your own methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

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

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

CST112 Looping Statements Page 1

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

[ the academy_of_code] Senior Beginners

Processing Boot Camp Control Structures. Key Compu6ng Ideas. Crea+ve Coding & Genera+ve Art in Processing 2 Ira Greenberg, Dianna Xu, Deepak Kumar

CST112 Variables Page 1

Solution Notes. COMP 151: Terms Test

if / if else statements

GRAPHICS PROGRAMMING. LAB #3 Starting a Simple Vector Animation

Processing Assignment Write- Ups

McGill University School of Computer Science COMP-202A Introduction to Computing 1

CISC 1600, Lab 3.2: Interactivity in Processing

Module 01 Processing Recap. CS 106 Winter 2018

1 Getting started with Processing

Computer Graphics. Interaction

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

Introduction to Processing

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

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

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

Iteration in Programming

The Junior Woodchuck Manuel of Processing Programming for Android Devices

Old 257 Exam #2s for Practice

Class Notes CN19 Class PImage Page

The Processing language. Arduino and Processing.

Module 05 User Interfaces. CS 106 Winter 2018

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

5.1. Examples: Going beyond Sequence

CISC 1600 Lecture 2.2 Interactivity&animation in Processing

Chapter 12: Functions Returning Booleans and Collision Detection

Lecture 8 CSE11 Fall 2013 While Loops, Switch Statement, Simplifying Conditionals

An Introduction to Processing

Module 01 Processing Recap

Java Programming. Computer Science 112

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

Methods (cont.) Chapter 7

Java Programming. Computer Science 112

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

EP486 Microcontroller Applications

Chapter 8. Classes and Objects

Object-Oriented Programming in Processing

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

CISC 1600, Lab 2.3: Processing animation, objects, and arrays

DRAWING AND MOVING IMAGES

Appendix: Common Errors

Variables and Control Structures. CS 110 Eric Eaton

Transcription:

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 top to bohom statement execujon - order mahers funcjon call syntax (e.g. rect(10,20,30,40); ) println() for debugging comments setup & draw system variables - mousex, pmousey, width, height, translate Did I leave off something important?

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

Variables store/remember values can be changed must be declared to store a parjcular kind of value (e.g. whole number, fracjon, character, color, image, boolean) should have a descripjve name start with leher then also include numbers no spaces

void setup() { size(500,500); nofill(); int diameter = 0; void draw() { ellipse(width/2, height/2, diameter,diameter); diameter = diameter + 10; 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)

// draw a simple house int housex = 50; int housey = 100; int housewidth = 100; rect(housex, housey, housewidth, housewidth/2); triangle(housex, housey, housex+housewidth/2, housey-housewidth/2, housex+housewidth, housey);

// draw a simple house int housex = 50; int housey = 100; int housewidth = 100; rect(housex, housey, housewidth, housewidth/2); triangle(housex, housey, housex+housewidth/2, housey-housewidth/2, housex+housewidth, housey); // draw another house - lines are copied from above housex = 200; housewidth = 50; rect(housex, housey, housewidth, housewidth/2); triangle(housex, housey, housex+housewidth/2, housey-housewidth/2, housex+housewidth, housey); // draw another house - lines are copied from above housex = 300; housey = 200; rect(housex, housey, housewidth, housewidth/2); triangle(housex, housey, housex+housewidth/2, housey-housewidth/2, housex+housewidth, housey);

void setup() { size(400,400); // draw a simple house float housex = 50; float housey = 100; float housewidth = 100; void draw() { rect(housex, housey, housewidth, housewidth/2); triangle(housex, housey, housex+housewidth/2, housey-housewidth/2, housex+housewidth, housey); housex = housex + 1.5*houseWidth; housey = housey + 0.75*houseWidth; housewidth = housewidth / 2;

/* Write a program that shows a 10x10 circle moving from the top center of the display down to the bottom center. */

/* Write a program that shows a 10x10 circle moving from the top center of the display down to the bottom center. */ //Can you make it go slower or faster?

void setup() { size(200, 200); void draw() { 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

Declaring v. IniJalizing v. Assigning int carfront; // declare int carfront = 100; // declare and inijalize carfront = carfront - 1; // assign

Modulus (%) 17 / 3 in Java is 5 (goes in evenly 5 Jmes) 17 % 3 in Java is 2 (17-3*5 = 2) What is 8 % 5? What is 150 % 10? What is 17 % 2?

int counter = 0; void draw() { background(255); int xpos = width - counter%width; int ypos = counter%height; fill(255,0,0); ellipse(xpos, ypos, 5, 5); fill(0,255,0); ellipse((2*counter)%width, (2*counter)%height, 5, 5); counter = counter + 1; A. The red one is moving faster. B. One is moving top to bottom following a diagonal, the other is moving bottom to top following a diagonal. C. Both A and B D. Neither A nor B

int frontofcar = 100; int topofcar = 100; int lengthofcar = 200; int carbodyheight = lengthofcar/4; int wheeldiameter = lengthofcar/4; // draw the body rect(frontofcar,topofcar,lengthofcar,carbodyheight); // draw the wheels ellipse(frontofcar+wheeldiameter,topofcar+carbodyheight, wheeldiameter,wheeldiameter); ellipse(frontofcar+lengthofcar-wheeldiameter, topofcar+carbodyheight, wheeldiameter,wheeldiameter); // draw the windshield // use carbodyheight to also control the size of the windshield line(frontofcar+carbodyheight,topofcar, frontofcar+2*carbodyheight, carbodyheight);

int frontofcar = 100; int topofcar = 100; int lengthofcar = 200; int carbodyheight = lengthofcar/4; int wheeldiameter = lengthofcar/4; void draw() { background(255); // 255 means white fill(255); // the inside of the body should be white // draw the body rect(frontofcar,topofcar,lengthofcar,carbodyheight); // draw the wheels ellipse(frontofcar+wheeldiameter,topofcar+carbodyheight, wheeldiameter,wheeldiameter); ellipse(frontofcar+lengthofcar-wheeldiameter, topofcar+carbodyheight,wheeldiameter,wheeldiameter); line(frontofcar+carbodyheight, topofcar, frontofcar+2*carbodyheight, topofcar-carbodyheight); frontofcar = frontofcar - 1; // move car to the left

int frontofcar = 100; int topofcar = 100; int lengthofcar = 100; int carbodyheight = lengthofcar/4; int wheeldiameter = lengthofcar/4; void draw() { println(lengthofcar); println(carbodyheight); println(wheeldiameter); background(255); // 255 means white fill(255); // the inside of the body should be white // draw the body... lengthofcar = lengthofcar - 1; // make the car shrink What is printed when the 2nd frame is drawn? A) 99 B) 99 C) 99 D) 100 25 24 24.75 25 25 24 24.75 25

PrimiJve Types 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 fracjonal parts 3.1415 double - like float but more precision

System Variables (Processing) mousex, mousey pmousex, pmousey width, height framecount

void setup() { size(400, 400); void draw() { fill(255-abs(mousex-pmousex)); rect(pmousex, pmousey, mousex, mousey);

void setup() { size(400, 400); // position A // position B void draw() { // 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.

Type Conversion/CasJng int housewidth; housewidth = housewidth *.75;

What is the value of x in int x, y = 7; x = y / 8; x = (-y) / 8; x = y / 3; x = y % 3; x = int(y*1.5); x = (int)y*1.5;

What is the value of z in int x = 6, y = 10; float z; z = x / y; A) 0 B).6 C) 1 D) none of the above - it is a syntax error

void setup() { size(500,500); fill(255,0, 0); void draw() { char letter = (char)('a' +random(26)); text(letter, mousex, mousey);

/*Author: Dustin Adams This program draws a square that changes color every frame and follows the mouse*/ float r; float g; float b; void setup() { size(400,400); background(150); void draw() { background(150); r = random(255); g = random(255); b = random(255); fill(r,g,b); rect(mousex,mousey,50,50);

The rules Variable Names start with a leher, _ or $ 2nd and on can also be a digit The guidelines descripjve start with lower case use camelcasetosetoffmuljplewords

Variables Recap declare globally if used to remember values from one call of draw() to the next declare within draw() (or setup()) if needed ONLY for that one execujon of method give the type only once, in the declarajon (which is different from an assignment)

void setup() { size(400,400); ypos = height; xpos = width/2; int xpos, ypos; void draw() { background(255); ellipse(xpos, ypos, 15, 15); ypos = ypos - 1; xpos = xpos - framecount/(height/2); A. The circle moves from bottom center to top center. B. The circle moves from bottom center to the middle, then diagonally to the upper left corner. C. The circle moves from the bottom center to the middle, then diagonally to the upper right corner. D. The circle moves from the bottom center to the middle then stops.