PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.

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.
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.
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ć
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.
Lesson Three: Organization
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.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
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?
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
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
PROCESSING Methods. Objectives Be able to define methods that return values Be able to define methods that do not return values Be able to use random.
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] |
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
© Calvin College, For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the.
Review Loops – Condition – Index Functions – Definition – Call – Parameters – Return value.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
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
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.
______________________________________________________________________________________ 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.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
B. RAMAMURTHY Processing and Programming cse
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 25, 2014 Carolyn Seaman Susan Martin.
Review Expressions and operators Iteration – while-loop – for-loop.
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.
Processing Variables. Variables Processing gives us several variables to play with These variables are always being updated and you can assume they have.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
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.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Chapter 7 Functions.
Computation as an Expressive Medium
Basic Input and Output CSE 120 Winter 2018
Chapter 7 Functions.
Chapter 10 Algorithms.
Mouse Inputs in Processing
Chapter 5, Conditionals Brief Notes
Chapter 10 Algorithms.
More programming with "Processing"
Game Loop Update & Draw.
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
LCC 6310 Computation as an Expressive Medium
Chapter 10 Algorithms.
Continuous & Random September 21, 2009.
Presentation transcript:

PROCESSING Animation

Objectives Be able to create Processing animations Be able to create interactive Processing programs

Example: Raindrops We’d like to make an animation where differently sized and differently colored circles appear throughout the output window Tools we already have: Color Ellipse

4 Defining Animation Methods Animation is an illusion created by presenting carefully designed image frames at a sufficient frame rate. For our first iteration, we’d like to draw circles appearing on the screen. For this, we need to: 1. Set up for the animation; 2. Draw each frame of the animation.

5 Methods In Processing, programmers add new operations by defining methods. Using methods helps us to: Modularize the program; Create helpful procedural abstractions; Improve readability; Encourage reuse. To build new methods, we’ll use the same IID approach we’ve used before.

Method Definition Pattern returnType methodName([parameterDeclarations]){ statements } returnType is the type of value returned by the method or void if the method does not return a value; methodName is the identifier that names the method; parameterDeclarations is a comma-separated list of parameter declarations of the form type identifier that is omitted if there are no parameters; statements is a set of statements that define the behavior of the method. 6

Animation Methods The programmer defines methods called setup() and draw() void setup(){... } void draw(){... } Processing calls these methods automatically setup() is run once when the program begins draw() runs repeatedly (once each frame) 7

Start simple: One raindrop void setup(){ size(300, 300); background(255); ellipse(150, 150, 30, 30); } But how will we make the circle change location?

Start simple: One raindrop void setup(){ size(300, 300); background(255); } void draw(){ ellipse(150, 150, 30, 30); } Draws the ellipse over and over again, once each frame, exactly the same each time

Moving Raindrops void setup(){ size(300, 300); background(255); } void draw(){ float x = random(300); float y = random(300); ellipse(x, y, 30, 30); }

How would you add color variation? void setup(){ size(300, 300); background(255); } void draw(){ float x = random(300); float y = random(300); ellipse(x, y, 30, 30); }

12 Defining Interaction Methods Processing supports user interaction using a set of pre- declared methods that respond to user-initiated events. User events include mouse and keyboard actions.

Interaction Using Mouse Methods mouseClicked() mouseDragged() mouseMoved() mousePressed() mouseReleased() Variables mouseX, mouseY, pMouseX, pMouseY mouseButton (LEFT, RIGHT, CENTER) mousePressed (boolean value) 13

Pause animation while mouse is pressed void setup(){ size(300, 300); background(255); } void draw(){ fill(random(255), random(255), random(255)); ellipse(random(300), random(300), 30, 30); } void mousePressed(){ noLoop(); } void mouseReleased(){ loop(); }

Interaction Using Keyboard Methods keyPressed() keyReleased() keyTyped() Variables key, keycode (which key was used) keyPressed (boolean value) 15

Clear Background 16 void keyPressed() { background(255); }

void setup(){ size(300, 300); background(255); } void draw(){ fill(random(255), random(255), random(255)); ellipse(random(300), random(300), 30, 30); } Exercise: Add differently sized circles

18 Example: Expanding Circles We’d like to build an interactive tool for drawing animated figures. The figures should include circles that grow/shrink. Some sample images are shown here.

Start simple void setup(){ size(300, 300); background(255); } void draw(){ ellipse(150, 150, 30, 30); } But how will we make the circle change size?

Start simple, then add complexity void setup(){ size(300, 300); background(255); } void draw(){ int diameter = 30; ellipse(150, 150, diameter, diameter); diameter = diameter + 2; } Resets diameter each frame!!

Start simple, then add complexity int diameter; // global variable! void setup(){ size(300, 300); background(255); diameter = 30; } void draw(){ ellipse(150, 150, diameter, diameter); diameter = diameter + 2; }

Variable Scope Local Variables Defined within another block. Not visible throughout the program. Global Variables Defined at the start of the program. Visible throughout the program since they are defined in the outermost block (they are not surrounded by any curly braces). 22

Global Variables and Animation Declare global variables at the top of your program (before setup) Initialize any global variables in setup() Use global variables throughout the rest of your program as needed for animation

24 final int WIDTH = 510, HEIGHT = WIDTH; float diameter; void setup() { size(WIDTH, HEIGHT); diameter = 0; } void draw() { background(255); float x = WIDTH/2, y = HEIGHT/2; ellipse(x, y, diameter, diameter); diameter += 2; }

Change Position of Animated Circle 25 void mousePressed() { figureX = mouseX; figureY = mouseY; diameter = 0; }

Animation Algorithms Break problem into groups: 1. What will need to be remembered from one frame to the next  Create a global variable for each piece 2. What should happen before the animation begins?  Put these steps in setup() 3. What should happen each frame?  Put these steps in draw() 4. What should happen based on interaction?  Put these steps in the appropriate method (mousePressed(), keyPressed(), etc)

Exercise Write an algorithm to animate a square that shakes in the middle of the screen Global variables setup() draw() Add the ability for the user to move the square to a new location based on a mouse click mouseClicked()