06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Check if point is inside of Stripe<br />

void rollover(int mx, int my) {<br />

// Left edge is x, Right edge is x + w<br />

if (mx > x & & mx < x + w) {<br />

mouse = true;<br />

} else {<br />

mouse = false;<br />

}<br />

}<br />

}<br />

Check <strong>to</strong> see if point (mx,my) is<br />

inside the Stripe.<br />

Arrays 157<br />

Exercise 9-8: Write a But<strong>to</strong>n class (see Example 5-5 for a non-object-oriented but<strong>to</strong>n). Th e but<strong>to</strong>n<br />

class should register when a mouse is pressed over the but<strong>to</strong>n and change color. Create but<strong>to</strong>n objects<br />

of diff erent sizes and locations using an array. Before writing the main program, sketch out the<br />

But<strong>to</strong>n class. Assume the but<strong>to</strong>n is off when it fi rst appears. Here is a code framework:<br />

class But<strong>to</strong>n {<br />

}<br />

float x;<br />

float y;<br />

float w;<br />

float h;<br />

boolean on;<br />

But<strong>to</strong>n(float tempX, float tempY, float tempW, float tempH) {<br />

x = tempX;<br />

y = tempY;<br />

w = tempW;<br />

h = tempH;<br />

on = __________;<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________<br />

_____________________________________________________________________

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!