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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

182 <strong>Learning</strong> <strong>Processing</strong><br />

// Display the raindrop<br />

void display() {<br />

// Display the drop<br />

noStroke();<br />

fill(c);<br />

for (int i = 2; i < r; i + + ) {<br />

ellipse(x,y + i*4,i*2,i*2);<br />

}<br />

}<br />

10.8 Integration: Puttin ’ on the Ritz<br />

It is time. Now that we have developed the individual pieces and confi rmed that each one works properly,<br />

we can assemble them <strong>to</strong>gether in one program. Th e fi rst step is <strong>to</strong> create a new <strong>Processing</strong> sketch that has<br />

four tabs, one for each of our classes and one main program, as shown in Figure 10.8 .<br />

fi g. 10.8<br />

Th e fi rst step is <strong>to</strong> copy and paste the code for each class in<strong>to</strong> each tab. Individually, they will not need <strong>to</strong><br />

change, so there is no need for us <strong>to</strong> revisit the code. What we do need <strong>to</strong> revisit is the main program—<br />

what goes in setup( ) and draw( ) . Referring back <strong>to</strong> the original game description and knowing how the<br />

pieces were assembled, we can write the pseudocode algorithm for the entire game.<br />

Setup:<br />

• Create Catcher object.<br />

• Create array of drops.<br />

• Set <strong>to</strong>talDrops equal <strong>to</strong> 0.<br />

• Create Timer object.<br />

• Start timer.<br />

D ra w :<br />

• Set Catcher location <strong>to</strong> mouse location.<br />

• Display Catcher.<br />

• Move all available Drops.<br />

• Display all available Drops.<br />

• If the Catcher intersects any Drop.<br />

– Remove Drop from screen.<br />

• If the timer is finished:<br />

– Increase the number of drops.<br />

– Restart timer.<br />

fi g. 10.7

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

Saved successfully!

Ooh no, something went wrong!