Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Lesson One: The Beginning Chapter 3: Interaction Learning Processing: by Daniel Shiffman Presentation by Donald W. Smith Graphics from text.
CS0007: Introduction to Computer Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
IAT 800 Foundations of Computational Art and Design Lecture 2.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
ICM Week 2. Structure - statements and blocks of code Any single statement ends with semicolon ; When we want to bunch a few statements together we use.
Lecture 3 IAT 800. Sept 15, Fall 2006IAT 8002 Suggestions on learning to program  Spend a lot of time fiddling around with code –Programming is something.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Continuous February 16, Test Review What expression represents the zip car eligibility rules of at least 18 years old and no incidents?
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Review Loops – Condition – Index Functions – Definition – Call – Parameters – Return value.
Concurrent Programming and Threads Threads Blocking a User Interface.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
JavaScript, Fourth Edition
Lesson Two: Everything You Need to Know
Often being different. Control flow By default Java (and therefore Processing) executes lines of a program one after the other –Doesn’t matter what happened.
LCC 6310 Computation as an Expressive Medium Lecture 2.
Repetition 8/9/2009. Learning to Program -- Suggestions Spend a lot of time fiddling around with code –Programming is something you have to learn by doing.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 23, 2014 Carolyn Seaman Susan.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Controlling Program Flow with Decision Structures.
Review Expressions and operators Iteration – while-loop – for-loop.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
Welcome to Processing Who does not have access to digital camera?
What is Computing? What can be Programmed? Creative Computing Processing Downloading Processing Dropbox Primitive Shapes – point – line – triangle – quad.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Introduction To Repetition The for loop
Computation as an Expressive Medium
Chapter 10 Algorithms.
Mouse Inputs in Processing
More programming with "Processing"
Introduction to Problem Solving & Programming using Processing 2
Lecture 7: Introduction to Processing
Lecture 8:The For Loop AP Computer Science Principles.
Variables & Datatypes CSE 120 Winter 2019
Introduction to Problem Solving & Programming using Processing 2
LCC 6310 Computation as an Expressive Medium
Lab1 Discussion B. Ramamurthy.
Chapter 10 Algorithms.
Trigonometry & Random March 2, 2010.
IAT 800 Foundations of Computational Art and Design
Continuous & Random September 21, 2009.
LCC 6310 Computation as an Expressive Medium
Introduction to Problem Solving & Programming using Processing 2
Presentation transcript:

Continuous

Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied only by loops and function calls. –Event Driven Programs run continuously responding to input events such as key strokes or mouse clicks.

How Do Those Classification Pertain to Our Class All the programs we have written or looked at so far are procedural. Today we look at event driven programs. First event driven program void draw() { frameRate(4); //fps = 4 println(frameCount); }

What Happened? About 4 times per second, a number (the frame count) was printed to the console window. Why? –There’s no for loop or while loop? The draw() function is processed continuously by the event handler until another event is triggered or you press the STOP button.

Next Program float y = 0; void draw() { frameRate(10); line(0, y, 100, y); y = y + 0.5; }

How Can We Produce the Following Sketch? Change the line y = y + 0.5; To y = y + 1.5;

More with Draw() To clear the window at every frame, put a background() command at the beginning of draw(). background() doesn’t have to use a constant value as its argument, change it to use an expression with y.

setup() For instructions that just need to be run once, use setup(). This is where you might –Set the screen size –Compute some “constants” –Set graphic characterics

setup() float y = 0; float increment = 0.5; void setup() { size (100, 100); smooth(); fill(0); } void draw() { frameRate(10); background(50+y*2); line(0, y, 100, y); if (y > height) increment *= -1.0; y = y + increment; }

Variable Scope What happens if you declare y –At the top –In draw –In setup

Scope When a variable will change in each iteration of draw, declare it outside of setup() and draw().

Why? When a variable is created within a code block, it can be used only within that block. It will be destroyed with the program leaves the block.

Think locally Adding variables outside of setup and draw “to be safe” makes your program harder to read For clarity, use the smallest possible scope

In-class Lab 1 Create a shape that moves from one side of the canvas to the other. When it reaches the opposite edge have it reverse direction and continue back and forth endlessly. For maximum credit make sure your code will work if the window size is set differently.

In-class Lab 2 Have your groundhog move around the screen And change size or color

Random Numbers Assume float f; To generate a pseudo random number between 0 and high and assign it to f f = random(high); To generate a pseudo random number between low and high f = random(low, high);

Printing Random Numbers for (int i=0; i<10; i++) { print(i + ". "); println(random(100)); } How do the print statements print and println differ? What’s the + inside of a print

Sample Code float f = random(5.2); // Assign f a float value from 0 to 5.2 int i = random(5.2); // ERROR! Can't assign a float to an int int j = (int)random(5.2); // Assign j an int value from 0 to 5

Sample Code smooth(); strokeWeight(10); stroke(0, 130); line(0, random(100), 100, random(100)); Modify the 5 method calls above to line() to use a for loop and one line() call. Why would a for be a better construct than a while ?

Sample Code smooth(); strokeWeight(20); stroke(0, 230); float r = random(5, 45); stroke(r * 5.6, 230); line(0, r, 100, random(55, 95)); r = random(5, 45); stroke(r * 5.6, 230); line(0, r, 100, random(55, 95)); r = random(5, 45); stroke(r * 5.6, 230); line(0, r, 100, random(55, 95)); Write the above code to use a for loop.

In-class Lab Begin with your face code which you can download from the student work section of the syllabus page. Modify some part of your face code so that one of your features changes in a random, yet somewhat realistic in a humanoid way.

Sample Code //lip points float lipPointLeftX = random(105,145); float lipPointRightX = random(171,211); //outer lip bezier(lipPointLeftX, 216, random(136,156), 213, random(157,177), 213, lipPointRightX, 216); bezier(lipPointLeftX, 216, random(150, 170), 261, random(181,209), 216, lipPointRightX, 216); //inner lip bezier(lipPointLeftX, 217, 148, 220, 167, 222, lipPointRightX, 216); bezier(lipPointLeftX, 217, 162, 245, 191, 216, lipPointRightX, 216);