Mouse Inputs in 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
 By carefully incrementing the X and/or Y values of our set of lines, we can create a game board for a boat game.  Lines that go from left to right are.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
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.
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.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
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?
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
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” 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.
Lesson Two: Everything You Need to Know
______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY [SIAT] |
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.
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,
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.
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.
Introduction to Processing David Meredith Aalborg University Art &Technology, 3rd Semester Programming.
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.
MOM! Phineas and Ferb are … Aims:
Some of Chap 17.
Basic Input and Output CSE 120 Spring 2017
Emerging Platform#1: Processing 3
p5.js mouse, keyboard and if’s
Chapter 14, Translate & Rotate
Lesson Two: Everything You Need to Know
“Processing” easy coding Jens Dalsgaard Nielsen
Introduction to processing
Computation as an Expressive Medium
Basic Input and Output CSE 120 Winter 2018
For Net Art Lecture 2 J Parker
Chapter 10 Algorithms.
Chapter 5, Conditionals Brief Notes
Chapter 10 Algorithms.
More programming with "Processing"
A Few Notes Starting August 29, 2018
Introduction to Problem Solving & Programming using Processing 2
Announcements How’s it going? My internet/power supply?
A Few Notes August 30, 2017.
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Basic Input and Output CSE 120 Winter 2019
Introduction to Problem Solving & Programming using Processing 2
LCC 6310 Computation as an Expressive Medium
Chapter 10 Algorithms.
Continuous & Random September 21, 2009.
Introduction to Problem Solving & Programming using Processing 2
Presentation transcript:

Mouse Inputs in Processing Fall 2009

Interacting with the Mouse mouseX and mouseY: pg 205-211 The position of the mouse in the canvas pmouseX and pmouseY: pg 208 The previous position of the mouse (in the last frame) mouseButton: pg 212-213 Which mouse button has pressed mousePressed: pg 212-213 true if the mouse button is pressed, false otherwise mousePressed() : pg 229-231 Functions that run when the mouse is pressed

Hello Mouse void setup() { size(400, 400); stroke(255); } void draw() { // try moving background() to setup() background(192, 64, 200); // mouseX is a variable that stores the horizontal position // of the mouse. // mouseY is a variable that stores the vertical position line(150, 25, mouseX, mouseY);

Moving with the Mouse // Circle follows the cursor void setup() { size(100, 100); smooth(); noStroke(); } void draw() { background(126); ellipse(mouseX, mouseY, 33, 33);

Highlighting with the Mouse // Cursor position selects a quadrant of the display window void setup() { size(100, 100); noStroke(); fill(0); } void draw() { background(204); if ((mouseX <= 50) && (mouseY <= 50)) { rect(0, 0, 50, 50); // Upper-left } else if ((mouseX <= 50) && (mouseY > 50)) { rect(0, 50, 50, 50); // Lower-left } else if ((mouseX > 50) && (mouseY < 50)) { rect(50, 0, 50, 50); // Upper-right } else { rect(50, 50, 50, 50); // Lower-right

pmouse // Draw a line between the current and previous positions void setup() { size(100, 100); strokeWeight(8); smooth(); } void draw() { background(204); // pmouseX is a variable that stores the horizontal position // of the mouse in the previous frame. // pmouseY is a variable that stores the vertical position of // the mouse in the previous frame. line(mouseX, mouseY, pmouseX, pmouseY);

mousePressed and mouseButton Like mouseX and mouseY, mousePressed is a property of the mouse (a variable), but it is of type boolean. The mousePressed variable stores true if any mouse button is pressed, and false otherwise. It reverts to false as soon as the button is released. The mouseButton variable is LEFT, CENTER, or RIGHT depending on the mouse button most recently pressed. mouseButton retains its value until a different mouse button is pressed

A Simple Paint Example int brushSize = 20; void setup() { smooth(); noStroke(); background(255); } void draw() { if (mousePressed) { brush(mouseX, mouseY); void brush(int x, int y) { fill(#CC3300); // note the color is specified as a hexadecimal number arc(x, y, brushSize, brushSize, 0, PI); fill(#003333); // note the color is specified as a hexadecimal number arc(x, y, brushSize, brushSize, PI, TWO_PI);

mousePressed() We can try to get the same functionality by using the mousePressed() event instead of the mousePressed variable. To use event, we need to write a function by the same name in our sketch, and it will be called automatically every time the event occurs. In the following code, mousePressed() will be called every time the mouse is pressed.

int brushSize = 20; void setup() { size(400, 400); smooth(); noStroke(); background(255); } void draw() { // keep the motor running void mousePressed() { brush(mouseX, mouseY); void brush(int x, int y) { fill(#CC3300); arc(x, y, brushSize, brushSize, 0, PI); fill(#003333); arc(x, y, brushSize, brushSize, PI, TWO_PI);

mousePressed vs. mousePressed() You'll notice that the program does not behave the same way. Although the mousePressed variable and the mousePressed() event have the same name, they represent different things mousePressed stores true for as long as the mouse button is down, whereas mousePressed() gets called once whenever the mouse becomes pressed, i.e. once per click.

In class exercise Create a recursive program that creates an aesthetically pleasing design. You can begin with code from the recursion powerpoint. Make the graphics appears in response to a mouse click or in some creative way use mouse input and recursion.