04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

388<br />

//inner window (top)<br />

rect(x+margin, y+margin, w-margin*2, winHt);<br />

//inner windows (bottom)<br />

rect(x+margin, y+winHt+margin*2, w-margin*2, winHt);<br />

break;<br />

case 2:<br />

winWdth = (w-margin*3)/2;<br />

winHt = (h-margin*3)/2;<br />

//outer window (sash)<br />

rect(x, y, w, h);<br />

//inner window (top-left)<br />

rect(x+margin, y+margin, winWdth, winHt);<br />

//inner window (top-right)<br />

rect(x+winWdth+margin*2, y+margin, winWdth, winHt);<br />

//inner windows (bottom-left)<br />

rect(x+margin, y+winHt+margin*2, winWdth, winHt);<br />

//inner windows (bottom-right)<br />

rect(x+winWdth+margin*2, y+winHt+margin*2, winWdth, winHt);<br />

break;<br />

}<br />

}<br />

// set window style (number of panes)<br />

void setStyle(int style){<br />

this.style = style;<br />

}<br />

}<br />

Figure 9-32. Drawing Some Windows sketch<br />

Although the Window class is longer than the Door class, it works very similarly. In the<br />

sketch, I created three windows, each with different features. The major difference<br />

between the Door <strong>and</strong> Window classes is the use of multiple constructors in the Window<br />

class. Remember that in <strong>Processing</strong>, you’re allowed to name multiple methods <strong>and</strong> functions<br />

with the same identifier, as long as their signatures are different. In OOP speak, this<br />

is called method overloading. It is quite common practice to do this with constructors, as

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

Saved successfully!

Ooh no, something went wrong!