Continuous & Random September 21, 2009.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

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.
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 Lab 1: Loops, Animation, and Simple User Interaction.
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.
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.
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.
______________________________________________________________________________________ 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.
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
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
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.
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.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
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?
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
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.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Scratch Programming Cards
Introduction to Event-Driven Programming
FOP: Buttons and Events
Introduction To Repetition The for loop
Scratch: iteration / repetition / loops
Iterative Constructs Review
Chapter 5: Control Structures II
Think What will be the output?
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Repetition-Counter control Loop
Lesson 1: Buttons and Events – 12/18
20 minutes maximum exhibits
Event Driven Programming
Computation as an Expressive Medium
Chapter 6 Loops (iteration).
CS 106A, Lecture 6 Control Flow and Parameters
Conditinoal Constructs Review
Mouse Inputs in Processing
Conditinoal Constructs Review
CHAPTER 6 GENERAL-PURPOSE METHODS
More programming with "Processing"
Introduction to Problem Solving & Programming using Processing 2
Lecture 8:The For Loop AP Computer Science Principles.
Introduction to Problem Solving & Programming using Processing 2
LCC 6310 Computation as an Expressive Medium
Lab1 Discussion B. Ramamurthy.
Suggested self-checks:
Chapter 4, Variables Brief Notes
Trigonometry & Random March 2, 2010.
IAT 800 Foundations of Computational Art and Design
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
LCC 6310 Computation as an Expressive Medium
Introduction to Problem Solving & Programming using Processing 2
Presentation transcript:

Continuous & Random September 21, 2009

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, pt 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(). float y = 0; float increment = 0.5;

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;

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.

In-class Lab 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.

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); 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);