09.04.2016 Views

www.ebook777.com

Make_Getting_Started_with_Processing_Second_Edition

Make_Getting_Started_with_Processing_Second_Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

84 Getting Started with Processing<br />

<strong>www</strong>.<strong>ebook777.com</strong><br />

Example 6-10: Isolating<br />

Transformations<br />

In this example, the smaller rectangle always draws in the same<br />

position because the translate(mouseX, mouseY) is cancelled by<br />

the popMatrix():<br />

void setup() {<br />

size(120, 120);<br />

}<br />

void draw() {<br />

pushMatrix();<br />

translate(mouseX, mouseY);<br />

rect(0, 0, 30, 30);<br />

popMatrix();<br />

translate(35, 10);<br />

rect(0, 0, 15, 15);<br />

}<br />

The pushMatrix() and popMatrix() functions are<br />

always used in pairs. For every pushMatrix(), you<br />

need to have a matching popMatrix().

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

Saved successfully!

Ooh no, something went wrong!