User Tools

Site Tools


courses:2008.23.09.intro_prototyping

oct 23: Introduction to programming with Processing: Inputs, mouse, keystrokes, audio, video.

Conditional statements

if condition

if (test) { 
  statements 
}

else condition

if(expression) { 
  statements 
} else { 
  statements 
} 

// also possible

if(expression) { 
  statements 
} else if(expression) { 
  statements 
} else { 
  statements 
}

Operators

&& (logical AND)
! (logical NOT)
|| (logical OR)

== (equality)
> (greater than)
>= (greater than or equal to)
!= (inequality)
< (less than)
<= (less than or equal to)

Inputs

How to control the code and build your logic/process/structure

Mouse
  • mouseButton accessible directly in the draw function mousePressed or in its own function mousePressed()
  • mouseReleased(), mouseMoved() and mouseDragged() also available
  • mouse coordinates: mouseX and mouseY
  • mouse coordinates of the previous frame: pmouseX and pmouseY
Keystroke
  • key vs keyCode
  • keyPressed() and keyReleased()
Audio
  • Using the Mimim library (included in Processing version 0152 and later)
  • See the included example Minim → getLineIn
Video
  • using the default Video library (please read all the information on the video page)
import processing.video.*;
Capture myCapture;

void setup() 
{
  size(640, 480);

  myCapture = new Capture(this, width, height, 30);
  
  // open the control panel for this device
  myCapture.settings();
  
  // The name of the capture device is dependent those
  // plugged into the computer. To get a list of the 
  // choices, uncomment the following line 
  // println(Capture.list());
  // And to specify the camera, replace "Camera Name" 
  // in the next line with one from Capture.list()
  // myCapture = new Capture(this, width, height, "Camera Name", 30);
}

void captureEvent(Capture myCapture) {
  myCapture.read();
}

void draw() {
  image(myCapture, 0, 0);
}
Others
courses/2008.23.09.intro_prototyping.txt · Last modified: 2008/10/22 13:18 by camille