Computation as an Expressive Medium

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

Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
Variables and Operators
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
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.
Loops – While, Do, For Repetition Statements Introduction to Arrays
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.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
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.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
The switch Statement, DecimalFormat, and Introduction to Looping
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
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.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
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] |
Lecture 4 Control Structures MIT – AITI What are Control Structures? Control structures are a way to alter the natural sequence of execution in.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
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.
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.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with 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.
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.
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
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.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Lecture 4b Repeating With Loops
Chapter 4 Repetition Statements (loops)
The switch Statement, and Introduction to Looping
Loop Structures.
Primitive Data, Variables, Loops (Maybe)
Lesson Two: Everything You Need to Know
CS106A, Stanford University
CS 106A, Lecture 14 Events and Instance Variables
Starting JavaProgramming
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Outline Altering flow of control Boolean expressions
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
We’re moving on to more recap from other programming languages
More programming with "Processing"
Chapter 6: Repetition Statements
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
February , 2009 CSE 113 B.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
LCC 6310 Computation as an Expressive Medium
Variables and Operators
Continuous & Random September 21, 2009.
LCC 6310 Computation as an Expressive Medium
Loops CGS3416 Spring 2019 Lecture 7.
Loops and Iteration CS 21a: Introduction to Computing I
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Computation as an Expressive Medium Lab 1: Loops, Animation, and Simple User Interaction Jason Alderman *Slides blatantly stolen from Mayhew Seavey. Yoinks!

http://www.lcc.gatech.edu/~mateas/courses/LCC6310-Fall2005/Syllabus2005.html Lab Hours Thanks for your responses! I’ll send out an e-mail by the end of the day with with lab hours. And always feel free to e-mail me if you have questions. I’m at gtg362v@mail.gatech.edu . (If you forget, it’ll be on the whiteboard in here.)

What have you gone over? Window size and coordinate system Commenting code Variables Drawing primitives point line rect ellipse triangle print() and println() if(boolean){ do something }else{ do something} logic (0,0) x y

What will we go over? Courseware! Variables: A Recap Drawing primitives (more info) Java Control Flow: Looping The Processing “draw()” looping function for animation Simple mouse interaction

Variables Variables are placeholders for your data. int i; // declares a new variable i i = 1; // assigns the value of 1 to the new variable int j = i + 1; // declares a new variable j, and assigns it to i + 1, which is 2.

Variables Two main types: Primitives and Objects Primitives: Objects: Boolean, Char, Byte, Short, Int, Long, Float, Double Objects: Everything else. Constructed with primitives as a base. For example, a “String” object is a series of Char variables.

More info on drawing primitives Zooooom on over to the reference pages…

Java Control Flow If-Then-Else: Conditional Logic int i = 5; if(i > 10) { save_the_kitten(); } else if(i > 3) { throw_the_kitten(); else { paint_the_kitten();

Java Control Flow: Looping Want to draw ten lines, evenly-spaced apart? line(10, 10, 10, 200); line(20, 10, 20, 200); line(30, 10, 30, 200); ... This can get old, fast. Also would be tedious if you wanted to change all of the lines to start 5 pixels higher, instead.

Java Control Flow: Looping Want to draw ten lines, evenly-spaced apart? What if we could run this same line of code multiple times, only changing these two numbers? line(10, 10, 10, 200); line(20, 10, 20, 200); line(30, 10, 30, 200); ... This can get old, fast. Also would be tedious if you wanted to change all of the lines to start 5 pixels higher, instead.

Java Control Flow: While Loops Holy Toledo! We can! Let’s use a while loop! int i = 10; while(i <= 100) { line(i, 10, i, 200); i = i + 10; } line(10, 10, 10, 200); line(20, 10, 20, 200); line(30, 10, 30, 200); ... A while loop will run the code inside the brackets repeatedly until the condition in the parentheses is false.

Java Control Flow: While Loops Be careful with loops. Make sure the condition will eventually return false, or else it will go forever. while(true) { ... } int i = 10; while(i > 0) { line(i, 10, i, 200); i = i + 10; } Both of these loops are valid, will compile, and run infinitely.

Java Control Flow: For Loops For Loops are just like While loops, but a bit more compact for simple incrementing, like in our last example. These two loops are functionally the same: int i = 10; while(i <= 100) { line(i, 10, i, 200); i += 10; } for(int i = 10; i <= 100; i += 10) { line(i, 10, i, 200); } (i += 10 is equivalent to i = i + 10)

Java Control Flow: Nested Loops Nesting of loops refers to putting one loop inside the brackets of another. for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } What does this mean? It means that the inside loop will run all the way through, then i will increment, and the inside loop will run again.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. Sets i to 10. That’s all for now. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. Sets j to 10. That’s all for now. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j i’s 10, j’s 10. Draws a point at (10, 10). Simple enough.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j Now we jump to the top of the innermost loop, and increment j by 10, and then check if it’s greater or equal to 100, which it’s not, so we continue.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j i is still 10, but j is now 20. We draw the new point, Then go to loop again.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j Aha. So we keep looping in this j loop until it passes 100. Then what?

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j Well, now that the program has exited from our j loop, It sees that it’s still inside our i loop, and increments i By 10.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j The program reaches the j loop again, so it loops All the way through drawing dots. Only this time, i is 20, so the dots are further to the right.

Java Control Flow: Nested Loops Still confused? Let’s look at this thing closer. i for(int i = 10; i <= 100; i += 10) { for(int j = 10; j <= 100; j += 10) { point(i, j); } j The i loop keeps incrementing in this way, drawing columns of dots, until i exceeds 100. The program then exits the code inside the i loop’s brackets.

Java Control Flow: Nested Loops Nested Loops are especially useful for drawing in grid formations in a 2-D space. Think about how you could nest another loop inside to make a grid in a 3-D space.

The draw() function What is the draw() function? Processing allows you to put code in a special function called draw, which will run a number of times per second. For any graphics that you want to change over time, or have the user interact with, you’ll need to use the draw() function.

The draw() function Simple example: float a = 200; void draw() { background(255); a = a - 1; if (a < 0) { a = height; } line(0, a, width, a);

The draw() function Simple example: float a = 200; void draw() { background(255); a = a - 1; if (a < 0) { a = height; } line(0, a, width, a); Important! The variable declaration must be outside the loop function, or else it will be reset every time draw() is called. (Try putting it inside draw() to see what happens)

The draw() function Simple example: float a = 200; void draw() { background(255); a = a - 1; if (a < 0) { a = height; } line(0, a, width, a); For animation, this line is necessary To clear the last frame that was drawn.

The draw() function Simple example: This is the meat of what makes the float a = 200; void draw() { background(255); a = a - 1; if (a < 0) { a = height; } line(0, a, width, a); This is the meat of what makes the line move. Each loop, we subtract 1 from the variable a, which we later use when drawing the line, so it will appear to move. When a is 0, we’ve hit the top of the window, and reset a to the highest value.

The setup() function You can use the setup() function to define some properties of your window once when your program first starts: size(width, height): size of drawing window (in pixels) framerate(fps): number of times per second that the draw() function is called. void setup() { size(640, 480); framerate(30); }

Tracking Mouse Position Processing uses two global variables which have the current mouse position at all times: mouseX, mouseY: current X and Y of cursor, relative to the top-left of drawing window. void draw() { background(204); line(mouseX, 20, mouseX, 80); } A simple program that moves a line left or right to follow your cursor. Note that it stops tracking your mouse when it’s not in the drawing window.

Reacting to Mouse Clicks Use the variable mousePressed. This simple function will draw a point in the window whenever the mouse is in the clicked position. Try clicking and dragging around the window and see what happens. Can you think of a way to make the drawing smoother? void draw() { if(mousePressed) { point(mouseX, mouseY); } There are similar variables for mouseReleased, mouseMoved, and mouseDragged.

That’s It For Today! For and While Loops Processing draw() function Mouse Position and Clicking Fig. 1: Ninja. http://www.lcc.gatech.edu/~mateas/courses/LCC6310-Fall2005/Syllabus2005.html