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

80<br />

Again, I always use the curly braces <strong>and</strong> will throughout the book. Getting back to the conditional<br />

statement in the bouncing ball sketch, I am actually checking for either of two<br />

conditions at the same time:<br />

if (xpos>=width-wdth/2 || xpos=starving){<br />

eatAnything();<br />

} else {<br />

eatWhatIsHealthy();<br />

}<br />

The if statement will execute the lines between the first pair of curly braces<br />

({ eatAnthing(); }) if the condition between the parentheses (hunger>=starving) is true.<br />

If the condition is false, the code following the else statement will execute<br />

({ eatWhatIsHealthy(); }). The conditional statement has two paths. You’ll soon realize<br />

that there are a number of ways in coding to do the same thing. Some uptight computer<br />

scientists might tell you that there is a most efficient way to write code, but I don’t totally<br />

buy that. Efficiency is a good thing, but you also need to find a style that suits your personality.<br />

For example, I could rewrite the preceding statements as follows:

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

Saved successfully!

Ooh no, something went wrong!