TECH 3601 New Media Programming
description
Transcript of TECH 3601 New Media Programming
![Page 1: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/1.jpg)
Chapter 3 Interaction
TECH 3601 NEW MEDIA PROGRAMMING
![Page 2: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/2.jpg)
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
![Page 3: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/3.jpg)
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
![Page 4: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/4.jpg)
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
![Page 5: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/5.jpg)
5
A scribble application
Learning Processing: Slides by Don Smith
Just keep connecting the points where the mouse was and it is now:
![Page 6: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/6.jpg)
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.
![Page 7: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/7.jpg)
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()
![Page 8: TECH 3601 New Media Programming](https://reader036.fdocuments.in/reader036/viewer/2022062401/56815e3c550346895dcca54c/html5/thumbnails/8.jpg)