8
Chapter 3 Interaction TECH 3601 NEW MEDIA PROGRAMMING

TECH 3601 New Media Programming

  • Upload
    hue

  • View
    52

  • Download
    0

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

Page 1: TECH 3601  New Media Programming

Chapter 3 Interaction

TECH 3601 NEW MEDIA PROGRAMMING

Page 2: 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

Page 3: TECH 3601  New Media Programming

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

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

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

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

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