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.

XMLElement diameterElement = children[i].getChild(0);<br />

int diameter = int(diameterElement.getContent());<br />

Data Input 351<br />

// Color is child 1<br />

The diameter is the content of the<br />

XMLElement colorElement = children[i].getChild(1); fi rst element while red and green<br />

int r = colorElement.getIntAttribute( "red");<br />

are attributes of the second.<br />

int g = colorElement.getIntAttribute( "green");<br />

// Make a new Bubble object with values from XML document<br />

bubbles[i] = new Bubble(r,g,diameter);<br />

}<br />

}<br />

void draw() {<br />

background(100);<br />

// Display and move all bubbles<br />

for (int i = 0; i � bubbles.length; i + + ) {<br />

bubbles[i].display();<br />

bubbles[i].drift();<br />

}<br />

}<br />

Exercise 18-13: Use the following XML document <strong>to</strong> initialize an array of objects. Design<br />

the objects <strong>to</strong> use all of the values in each XML element. (Feel free <strong>to</strong> rewrite the XML<br />

document <strong>to</strong> include more or less data.) If you do not want <strong>to</strong> retype the XML, it is available<br />

at this book’s web site.<br />

� ?xml version = "1.0"? �<br />

� blobs �<br />

� blob �<br />

� location x = "99" y = " 192"/ �<br />

� speed x = " � 0.88238335 " y = " 2.2704291"/ �<br />

� size w = "38" h = " 10"/ �<br />

� /blob �<br />

� blob �<br />

� location x = "97" y = "14" / �<br />

� speed x = " 2.8775783 " y = " 2.9483867 "/ �<br />

� size w = "81" h = "43" / �<br />

� /blob �<br />

� blob �<br />

� location x = " 159 " y = " 193 " / �<br />

� speed x = " -1.2341062 " y = " 0.44016743 " / �<br />

� size w = "19" h = "95" / �<br />

� /blob �<br />

� blob �

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

Saved successfully!

Ooh no, something went wrong!