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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

472<br />

getters/setters<br />

Finishing the class are getter <strong>and</strong> setter methods for the instance properties. You’ll learn<br />

more about the benefit of getters <strong>and</strong> setters in Chapter 14, when I show you how to work<br />

in Java mode. For now, you can access instance properties directly, as in rg.c1 (assuming<br />

rg is the name of the gradient object), or using the method rg.getColor1().<br />

LinearGradient class<br />

class LinearGradient extends Gradient {<br />

int axis;<br />

//default constructor<br />

LinearGradient() {<br />

axis = AXIS_VERTICAL;<br />

}<br />

//constructor<br />

LinearGradient(color c1, color c2) {<br />

this.c1 = c1;<br />

this.c2 = c2;<br />

axis = AXIS_VERTICAL;<br />

}<br />

//constructor<br />

LinearGradient(color c1, color c2, Rectangle bounds) {<br />

this.c1 = c1;<br />

this.c2 = c2;<br />

this.bounds = bounds;<br />

axis = AXIS_VERTICAL;<br />

}<br />

//constructor<br />

LinearGradient(color c1, color c2, Rectangle bounds, int axis) {<br />

this.c1 = c1;<br />

this.c2 = c2;<br />

this.bounds = bounds;<br />

this.axis = axis;<br />

}<br />

// required: implemented create method<br />

void create(){<br />

// calculate differences between color components<br />

float deltaR = red(c2)-red(c1);<br />

float deltaG = green(c2)-green(c1);<br />

float deltaB = blue(c2)-blue(c1);

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

Saved successfully!

Ooh no, something went wrong!