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.

In laying out the neighborhood, I used the previous house’s x <strong>and</strong> w positions to ensure<br />

that the houses lined up properly, but also didn’t overlap.<br />

In spite of the sketch’s length (when the four classes are added), the object-oriented structure<br />

adds organization <strong>and</strong> (reusable) modularity to the code, as compared to a long series<br />

of function calls. In addition, the OOP structure provides a logical framework in which to<br />

add new features to the entire neighborhood, the House class, or any of the component<br />

classes. Really take your time going through (<strong>and</strong> playing) with this example. I also suggest<br />

trying to reimplement some of the internal drawing methods. For example, the cathedral<br />

roof could be drawn with <strong>Processing</strong>’s triangle() function, <strong>and</strong> the dome roof could be<br />

created with the bezier() or curve() function. Changing the internal implementation of<br />

a class, if done properly, should have no effect on how you use the class. In addition (if<br />

you’re feeling ambitious), you could even try to apply a tessellated texture as a skin to<br />

some of the houses.<br />

/*<br />

Neighborhood<br />

Ira Greenberg, January 1, 2006<br />

Happy New Year!<br />

*/<br />

void setup(){<br />

size(600, 400);<br />

background(190);<br />

smooth();<br />

//ground plane<br />

int groundHeight = 10;<br />

fill(0);<br />

rect(0, height-groundHeight, width, groundHeight);<br />

fill(255);<br />

// Houses<br />

Door door1 = new Door(40, 80);<br />

Window window1 = new Window(100, 125, false, Window.DOUBLE);<br />

Roof roof1 = new Roof(Roof.DOME);<br />

House house1 = new House(150, 150, door1, window1, roof1, ➥<br />

House.MIDDLE_DOOR);<br />

house1.drawHouse(50, height-groundHeight-house1.h, true);<br />

Door door2 = new Door(40, 80);<br />

Window window2 = new Window(100, 125, true, Window.QUAD);<br />

Roof roof2 = new Roof(Roof.GAMBREL);<br />

House house2 = new House(200, 120, door2, window2, roof2, ➥<br />

House.LEFT_DOOR);<br />

house2.drawHouse(50+house1.w, height-groundHeight-house2.h, true);<br />

Door door3 = new Door(40, 80);<br />

door3.setKnob(Door.RT);<br />

Window window3 = new Window(125, 125, true, Window.SINGLE);<br />

SHAPES<br />

395<br />

9

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

Saved successfully!

Ooh no, something went wrong!