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

Create successful ePaper yourself

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

create new rectangle object<br />

r1 = new Rectangle(100, 200, 150, 150);<br />

}<br />

// class description<br />

class Rectangle {<br />

//class constructor<br />

Rectangle(int x, int y, int w, int h) {<br />

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

}<br />

}<br />

Figure 9-30. Drawing with OOP sketch<br />

Creating a neighborhood<br />

Hopefully, this last sketch makes some sense. Don’t worry if it doesn’t yet. Also, you’d be<br />

correct in thinking that it doesn’t really make much sense to go through the bother of<br />

creating a class just to call rect(), which you could call from within setup(). This is certainly<br />

true. So let’s add some stuff to make all this class business worth it. Let’s build a<br />

simple house, with a door, some windows, <strong>and</strong> a roof, <strong>and</strong> then let’s put a couple houses<br />

together to form a little neighborhood. I’m going to make a class for each of the following<br />

elements: door, window, roof, <strong>and</strong> house. In this example, I’ll keep things simple by not<br />

adding decorative features like paint, shingles, cornices, <strong>and</strong> so on. And I’ll keep all the<br />

classes within the same PDE file (which isn’t really necessary). Later in the book, I’ll show<br />

you how to begin working with multiple files in separate <strong>Processing</strong> tabs.<br />

SHAPES<br />

381<br />

9

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

Saved successfully!

Ooh no, something went wrong!