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 />

312<br />

should not be targeted directly <strong>and</strong> the properties should actually be made private, using<br />

the optional private keyword (called an access modifier) in front of the property declaration.<br />

For example<br />

private String meatType<br />

If you make the property private, you will not be allowed to directly target it from outside<br />

the class. Instead, you are forced to use its respective public get/set methods.<br />

So, instead of myBurritoRecipe.meatType = "chicken" or String meat = myBurritoRecipe.<br />

meatType;, classic OOP says you must use myBurritoRecipe.setMeatType("chicken"); or<br />

String meat = myBurritoRecipe.getMeatType();—I suspect this might be confusing, so<br />

for now, you can go ahead <strong>and</strong> be naughty <strong>and</strong> just target your properties directly, which<br />

is actually encouraged in <strong>Processing</strong>.<br />

In addition to the getter <strong>and</strong> setter methods, most classes also have additional methods<br />

that do more interesting things (thank goodness). For example, the printRecipe()<br />

method in this program outputs burrito cooking instructions.<br />

void printRecipe(){<br />

println("Burrito Recipe:");<br />

println("---------------");<br />

if (this.tortillaFlavor!=null){<br />

println("Steam or lightly pan heat a " + this.tortillaFlavor + ➥<br />

" tortilla.");<br />

if (this.beanType!=null){<br />

println("Sauté fresh onions, garlic, cilantro, slowly ➥<br />

mixing in " + this.beanType + " beans <strong>and</strong> white wine.");<br />

}<br />

if (this.meatType!=null){<br />

println("Grill " + this.meatType+" along with fresh green ➥<br />

pepper, jalapeno pepper, chile pepper, onions <strong>and</strong> garlic.");<br />

}<br />

if (this.toppings!=null){<br />

for (int i =0; i< toppings.length; i++){<br />

println("Add " + toppings[i]+".");<br />

}<br />

}<br />

if (this.salsaTemperature>0){<br />

println("Finish off with a generous spritz of " + ➥<br />

this.salsaTemperature+" alarm salsa.");<br />

}<br />

}<br />

else {<br />

println("Uh, you'll need to give me some ingredients\n" + ➥<br />

"if you actually want me to produce a recipe.");<br />

}<br />

// go to next line after printing<br />

// cooking instructions to the screen

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

Saved successfully!

Ooh no, something went wrong!