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.

fi g. 23.2<br />

Java 427<br />

Just as with the <strong>Processing</strong> reference, the Java page includes an explanation of what the class does, the<br />

Construc<strong>to</strong>rs for creating an object instance, and available fi elds (variables) and methods (functions). Since<br />

Random is part of the java.util package (which <strong>Processing</strong> imports by assumption), we do not need <strong>to</strong><br />

explicitly write an import statement <strong>to</strong> use it.<br />

Here is some code that makes a Random object and calls the function nextBoolean( ) on it <strong>to</strong> get a<br />

random true or false.<br />

Example 23-1: Using java.util.Random instead of random()<br />

Random r;<br />

void setup() {<br />

size(200,200);<br />

r = new Random();<br />

}<br />

Declaring a Random object and<br />

calling the construc<strong>to</strong>r as found<br />

at http://java.sun.com/j2se/1.4.2/<br />

docs/api/java/util/Random.html

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

Saved successfully!

Ooh no, something went wrong!