Upload
hue
View
52
Download
0
Tags:
Embed Size (px)
DESCRIPTION
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. - PowerPoint PPT Presentation
Citation preview
Chapter 3 Interaction
TECH 3601 NEW MEDIA PROGRAMMING
2
setup()and draw()methods•When your program starts, Processing:• Calls setup() once• Continues to call draw() until
the program ends
Learning Processing: Slides by Don Smith
Program Starts
Call setup()
Call draw()
Program ends
Done yet?
Yes
No
3
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
4
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
5
A scribble application
Learning Processing: Slides by Don Smith
Just keep connecting the points where the mouse was and it is now:
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.
7
Mouse clicks and Key presses
Learning Processing: Slides by Don Smith
Two ‘methods’ that you can write to handle events that might happen:
Processing ‘calls’ your method when events occur: mousePressed()
keyPressed()