CIS 3.5 Lecture 2.2 More programming with "Processing"

Slides:



Advertisements
Similar presentations
Creative Computing. \\ aims By the end of the session you will be able to: 1.Move objects around 2.Write simple interactive programs 3.Use the mouse position.
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.
Introduction to Programming
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
A Quick Introduction to Processing
Variables and Operators
Emerging Platform#5: Processing 2 B. Ramamurthy 6/13/2014B. Ramamurthy, CS6511.
© Calvin College, Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create.
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
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.
Sketchify Tutorial Graphics and Animation in Sketchify sketchify.sf.net Željko Obrenović
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
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.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 1 Introduction to Processing.
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.
G RAPHICS P ROGRAMMING Lecture 3 - Simple Animation - Simple 3D Drawing.
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?
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.
Processing Lecture.2 Mouse and Keyboard
Review of ArT3 Programming Course David Meredith Aalborg University
Introduction to Processing CS 4390/5390 Fall 2014 Shirley Moore, Instructor September 3,
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
Mouse Inputs in Processing. Interacting with the Mouse mouseX and mouseY: pg mouseXmouseY –The position of the mouse in the canvas pmouseX and.
Lesson Two: Everything You Need to Know
Test 2 Review. General Info. All tests are comprehensive. You are still responsible for the material covered prior to the first exam. You will be tested.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
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.
Computer Science I Share plans for virtual something. Text. Show my virtual dog. Classwork: Plans for your virtual something. Homework: start implementation.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
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?
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
What is Computing? What can be Programmed? Creative Computing Processing Downloading Processing Dropbox Primitive Shapes – point – line – triangle – quad.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Arrays. 2 Why do we care (about arrays)? What if you have a whole bunch of cars (or aliens or balls or ???) bouncing around the screen? How do we keep.
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.
Computation as an Expressive Medium
For Net Art Lecture 2 J Parker
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
More programming with "Processing"
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
LCC 6310 Computation as an Expressive Medium
Continuous & Random September 21, 2009.
Presentation transcript:

CIS 3.5 Lecture 2.2 More programming with "Processing"

Resources Processing web site: Linear motion: Sequential animation: Reference:

Variables variables provide a way to save information within your sketch and use it to control the position, size, shape, etc of what you are drawing variables have a data type, a name and a value valid data types are: o int — for storing integers (whole numbers) o float — for storing floating point (real) numbers o boolean — for storing true or false values o char — for storing single characters o String — for storing multiple (strings of) characters example: int x1 = 10; int y1 = 10; int x2 = 20; int y2 = 20; line( x1, y1, x2, y2 );

Looping loops are used for doing things repeatedly there are two basic types of loops: o for loops o while loops loops are handy for animation, because you typically want to display things repeatedly when you are doing animation looping is a type of: o repetition (required element of imperative programming) o iteration (same thing as repetition)

for loops for loops repeat things for a fixed number of times syntax: for ( init; test; update ) { statements } example: int x = 10; int y1 = 10; int y2 = 20; for ( int i=0; i<10; i++ ) { line( x, y1, x, y2 ); x = x + 10; }

while loops while loops repeat things as long as a condition holds true syntax: while ( expression ) { statements } example: int x = 10; int y1 = 30; int y2 = 40; while ( x < width ) { line( x, y1, x, y2 ); x = x + 10; }

Standard Processing Program 1.Setup any variables or classes you are going to use. 2.Use setup() function to specify things to do once, when the sketch first opens 3.Use draw() function to specify things to do repeatedly o use frameRate() function to specify how often things should be repeated in draw(); o default frame-rate is 60 (60 frames per second) o NOTE: call to frameRate() should be done inside setup() function 4.Declare and event-listeners that you are going to use. 5.Declare any custom made functions you are going to use. 6.Declare any classes that you are going to use. Note: I have created a processing template that you can use to start your programs.

Animation Basic animation involves the following steps: 1.Drawing initial frame - perhaps in setup(). 2.Waiting some amount of time (e.g., 1/60th of a second) o Processing does that automatically 3.Erasing the screen. o Usually be reapplying the background (draw does this automatically). 4.Drawing the next frame. 5.Repeating steps 2-4, until you are ready to stop animating. There are two basic ways to implement animation: 1.Drawing your own shapes, text, etc. 2.Displaying a GIF or other image file

Vector Animation (drawing shapes) From float a = 100; void setup() { size( 640, 200 ); stroke( 255 ); } void draw() { background( 51 ); a = a - 0.5; if ( a < 0 ) { a = height; } line( 0, a, width, a ); }

Bitmap Animation (using pictures) int numFrames = 4; // The number of frames in the animation int frame = 0; PImage[ ] images = new PImage[numFrames]; void setup() { size( 200, 200 ); frameRate( 30 ); images[0] = loadImage("PT_anim0000.gif"); images[1] = loadImage("PT_anim0001.gif"); images[2] = loadImage("PT_anim0002.gif"); images[3] = loadImage("PT_anim0003.gif"); } void draw() { frame = ( frame + 1 ) % numFrames; // Use % to cycle through frames image( images[frame], 50, 50 ); }

Movement and Animation int xPos = 0; int yPos = 50;.... void draw() { xPos = (xPos + 2) % width; frame = ( frame + 1 ) % numFrames; // Use % to cycle through frames image( images[frame], xPos, yPos ); }... void keyPressed() { if (key == CODED) { if (keyCode == UP) { yPos = yPos - 2; } else if (keyCode == DOWN) { yPos = yPos + 2; } } }

Mouse Interaction mouseX and mouseY o indicate (x, y) location of mouse pointer mouseClicked() o handles behavior when user clicks mouse button (press and release) mouseMoved() o handles behavior when user moves mouse (moves it without pressing button) mouseDragged() o handles behavior when user drags mouse (moves it with button pressed) mouseButton o indicates which button was pressed, on a multi-button mouse (on a Mac, use Cntl-click for left mouse button, Alt-click for middle mouse button and Apple-click for right mouse button)

Example 1 (mouse location) void setup() { size( 200, 200 ); } void draw() { background( #cccccc ); // What happens if you remove the line above? fill( # ); rect( mouseX, mouseY, 20, 20 ); }

Example 2 (mouseMoved) void setup() { size( 200, 200 ); } void draw() { background( #cccccc ); fill( # ); rect( mouseX, mouseY, 20, 20 ); } void mouseMoved() { fill( # ); rect( mouseX, mouseY, 20, 20 ); } /* how does this behave differently from the mouse location example? */

Example 3 (mouseDragged) void setup() { size( 200, 200 ); } void draw() { background( #cccccc ); fill( # ); rect( mouseX, mouseY, 20, 20 ); } void mouseMoved() { fill( # ); rect( mouseX, mouseY, 20, 20 ); } void mouseDragged() { fill( # ); rect( mouseX, mouseY, 20, 20 ); } /* how does this behave differently from the previous two examples? */

Example #4 (mouseClicked) int r = 0; int g = 0; int b = 0; void setup() { size( 200, 200 ); } void draw() { background( #ffffff ); fill( r, g, b ); rect( 50, 50, 20, 20 ); } void mouseClicked() { r = r + 51; if ( r > 255 ) { r = 0; g = g + 51; if ( g > 255 ) { g = 0; b = b + 51; if ( b > 255 ) { b = 0; } } } println( "r=" + r + " g=" + g + " b=" + b ); }

Example #5 (mouseButton) void setup() { size( 200, 200 ); } void draw() { background( #cccccc ); rect( mouseX, mouseY, 20, 20 ); } void mousePressed() { if ( mouseButton == LEFT ) { fill( # ); } else if ( mouseButton == CENTER ) { fill( # ); } else if ( mouseButton == RIGHT ) { // Ctrl-click on mac fill( # ); }