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.

stroke(0);<br />

fill(175);<br />

ellipse(0,0,diameter,diameter);<br />

// Afer we are done, res<strong>to</strong>re matrix!<br />

popMatrix();<br />

}<br />

}<br />

Once the planet is drawn, the matrix<br />

is res<strong>to</strong>red with popMatrix() so that<br />

the next planet is not affected.<br />

Translation and Rotation (in 3D!) 251<br />

Exercise 14-10: How would you add moons <strong>to</strong> the planets? Hint: Write a Moon class that<br />

is virtually identical <strong>to</strong> the Planet. Th en, incorporate a Moon variable in<strong>to</strong> the Planet class.<br />

(In Chapter 22, we will see how this could be made more effi cient with advanced OOP<br />

techniques.)<br />

Exercise 14-11: Extend the solar system example in<strong>to</strong> three dimensions. Try using sphere( )<br />

or box( ) instead of ellipse( ) . Note sphere( ) takes one argument, the sphere’s radius. box( ) can<br />

take one argument (size, in the case of a cube) or three arguments (width, height, and depth.)

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

Saved successfully!

Ooh no, something went wrong!