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.

constructor<br />

Door(int w, int h){<br />

this.w = w;<br />

this.h = h;<br />

}<br />

// draw the door<br />

void drawDoor(int x, int y) {<br />

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

int knobsize = w/10;<br />

if (knobLoc == 0){<br />

//right side<br />

ellipse(x+w-knobsize, y+h/2, knobsize, knobsize);<br />

}<br />

else {<br />

//left side<br />

ellipse(x+knobsize, y+h/2, knobsize, knobsize);<br />

}<br />

}<br />

// set knob position<br />

void setKnob(int knobLoc){<br />

this. knobLoc = knobLoc;<br />

}<br />

}<br />

The three lines at the top of the sketch create the door.<br />

door1 = new Door(100, 250);<br />

door1.setKnob(Door.LFT);<br />

door1.drawDoor(50, 50);<br />

Figure 9-31. Drawing a Door sketch<br />

SHAPES<br />

385<br />

9

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

Saved successfully!

Ooh no, something went wrong!