80 likes | 245 Views
TECH 3601 New Media Programming . Chapter 3 Interaction. setup() and draw() methods. Program Starts. When your program starts, Processing: Calls setup() once Continues to call draw() until the program ends. Call setup(). Call draw(). No. Done yet?. Yes. Program ends.
E N D
TECH 3601 New Media Programming Chapter 3 Interaction
setup()and draw()methods Program Starts • When your program starts, Processing: • Calls setup() once • Continues to call draw() until the program ends Call setup() Call draw() No Done yet? Yes Program ends Learning Processing: Slides by Don Smith
Tracking the Mouse • Processing keeps track of where the mouse is: • mouseX: The current X coordinate of the mouse • mouseY: The current Y coordinate of the mouse • These are both ‘key words’ that you can use! • Their values change as the mouse moves • An example: Learning Processing: Slides by Don Smith
More Mouse tracks… • Processing also keeps track of where the mouse WAS the last time you left draw(): • pmouseX: The previous X coordinate of the mouse • pmouseY: The previous Y coordinate of the mouse Learning Processing: Slides by Don Smith
A scribble application • Just keep connecting the points where the mouse was and it is now: Learning Processing: Slides by Don Smith
Exercise • To get the absolute value: abs(-5) 5 • The speed at which the mouse is moving is: • abs(mouseX - pmouseX) • Update the previous example so that the faster the user moves the mouse, the wider the drawn line. • Hint: look up strokeWeight() in the Processing reference.
Mouse clicks and Key presses • Two ‘methods’ that you can write to handle events that might happen: • Processing ‘calls’ your method when events occur: • mousePressed() • keyPressed() Learning Processing: Slides by Don Smith