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.

Hint: Add a function that returns a boolean in the Particle class.<br />

ArrayList particles<br />

fi g. 23.4<br />

_______ finished() {<br />

}<br />

if (_______) {<br />

return _______;<br />

} else {<br />

}<br />

return false;<br />

C is removed....<br />

Particle<br />

A<br />

Particle<br />

B<br />

Particle<br />

C<br />

Particle<br />

D<br />

0 1 2<br />

3 4<br />

Particle<br />

E<br />

size = 5 size = 4<br />

Particle<br />

A<br />

Particle<br />

B<br />

Particle<br />

D<br />

Particle<br />

E<br />

0 1 2 3<br />

Java 431<br />

Exercise 23-2 : Rewrite Example 23-2 so that particles are removed from the list whenever<br />

they leave the window (i.e., their y location is greater than height).<br />

Hint: In order for this <strong>to</strong> work properly, you must iterate through elements of the ArrayList<br />

backward! Why? Because when an element is removed, all subsequent elements are shifted <strong>to</strong> the<br />

left (see Figure 23.4 ).<br />

for (int i = _______; i _______; i_______) {<br />

}<br />

Particle p = (Particle) particles.get(i);<br />

p.run();<br />

p.gravity();<br />

p.render();<br />

if (_______) {<br />

}<br />

_______;

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

Saved successfully!

Ooh no, something went wrong!