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

Lesson One: The Beginning Chapter 3: Interaction Learning Processing: by Daniel Shiffman Presentation by Donald W. Smith Graphics from text.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
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
© 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.
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
______________________________________________________________________________________ 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.
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.
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.
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.
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.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
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.
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.
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.
Task 1 and Task 2. Variables in Java Programs Variables start with lower case letter Variables are descriptive of what they store Variables are one word.
CS 134 Alternate Inputs.
MOM! Phineas and Ferb are … Aims:
Basic Input and Output CSE 120 Spring 2017
p5.js mouse, keyboard and if’s
Lesson Two: Everything You Need to Know
Control Structures
Computation as an Expressive Medium
Basic Input and Output CSE 120 Winter 2018
Arrays, For loop While loop Do while loop
For Net Art Lecture 2 J Parker
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
A Few Notes Starting August 29, 2018
Control structures Chapter 3.
A Few Notes August 30, 2017.
Control structures Chapter 3.
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Basic Input and Output CSE 120 Winter 2019
Control structures Chapter 3.
LCC 6310 Computation as an Expressive Medium
Variables and Operators
Continuous & Random September 21, 2009.
CSC 221: Introduction to Programming Fall 2018
Web Programming and Design
Presentation transcript:

More programming with "Processing" CIS3.5 Spring 2010 Lecture II.2 More programming with  "Processing"

Resources • Processing web site:     http://www.processing.org/ • Linear motion:      http://www.processing.org/learning/topics/linear.html • Sequential animation:     http://www.processing.org/learning/topics/sequential.html • Reference:      http://www.processing.org/reference/index.html

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: int — for storing integers (whole numbers) float — for storing floating point (real) numbers boolean — for storing true or false values char — for storing single characters 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:  for loops  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: repetition (required element of imperative programming) 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 Setup any variables or classes you are going to use. Use setup() function to specify things to do once, when the sketch first opens Use draw() function to specify things to do repeatedly use frameRate() function to specify how often things should be repeated in draw(); default frame-rate is 60 (60 frames per second) NOTE: call to frameRate() should be done inside setup() function Declare and event-listeners that you are going to use. Declare any custom made functions you are going to use. 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: Drawing initial frame - perhaps in setup(). Waiting some amount of time (e.g., 1/60th of a second) Processing does that automatically Erasing the screen.  Usually be reapplying the background (draw does this automatically). Drawing the next frame. Repeating steps 2-4, until you are ready to stop animating.   There are two basic ways to implement animation: Drawing your own shapes, text, etc. Displaying a GIF or other image file

Vector Animation (drawing shapes) From http://www.processing.org/learning/topics/linear.html 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) http://www.processing.org/learning/topics/sequential.html  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 indicate (x, y) location of mouse pointer mouseClicked() handles behavior when user clicks mouse button (press and release) mouseMoved() handles behavior when user moves mouse (moves it without pressing button) mouseDragged() handles behavior when user drags mouse (moves it with button pressed) mouseButton 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( #000099 ); rect( mouseX, mouseY, 20, 20 );

Example 2 (mouseMoved) void setup() { size( 200, 200 ); } void draw() { background( #cccccc ); fill( #990000 ); rect( mouseX, mouseY, 20, 20 ); } void mouseMoved() { fill( #000099 ); 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( #990000 ); rect( mouseX, mouseY, 20, 20 ); } void mouseMoved() { fill( #000099 ); rect( mouseX, mouseY, 20, 20 ); } void mouseDragged() { fill( #009900 ); 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( #990000 ); } else if ( mouseButton == CENTER ) { fill( #009900 ); } else if ( mouseButton == RIGHT ) {   // Ctrl-click on mac fill( #000099 ); }