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.

message comes up on the bar in the message area of the <strong>Processing</strong> editor window that<br />

says Expecting SEMI . . .. Fortunately, the <strong>Processing</strong>/Java compiler is smart <strong>and</strong> keeps you<br />

from making too big a goof-up. If you happened to try this, just put the semicolon back,<br />

<strong>and</strong> the program should compile fine. You’ll notice almost all the rest of the lines of the<br />

program have the same basic structure, each calling a function. As I mentioned previously,<br />

the line // keeps a stroke from showing up around the circle is a single-line comment.<br />

The line noStroke(); is a function call that doesn’t pass any arguments. noStroke()<br />

affects how things are painted to the screen. The function call disables a stroke or outline<br />

from being rendered on a shape. I’ll be covering <strong>Processing</strong>’s drawing <strong>and</strong> painting functions<br />

a lot in future chapters. The line print("Hello Earth!"); is a call to the print()<br />

function that expects an argument of type String. In this case, you passed in your "Hello<br />

Earth!" argument. You should have seen the words Hello Earth come up in the black text<br />

area at the bottom of the <strong>Processing</strong> editor window. String is a type of data in <strong>Processing</strong><br />

(or most any program) for referencing groups of characters. print() is an important function<br />

that you’ll use all the time in <strong>Processing</strong> to help you debug your code. <strong>Processing</strong> has<br />

an alternate version, println(), which does the same thing as print(), but adds a return<br />

after printing the string argument within the parentheses. For example, if you run the following<br />

code:<br />

print("hello");<br />

print("earth");<br />

the output will be as follows:<br />

helloearth<br />

If you use the println() version, as follows:<br />

println("hello");<br />

println("earth");<br />

the output will look like this:<br />

hello<br />

earth<br />

The rest of the function calls in the program, Background(0), fill(80, 220, 255), <strong>and</strong><br />

ellipse(100, 100, 100, 100), set the background color, set the shape fill color, <strong>and</strong> create<br />

the circle, respectively. I will be covering these <strong>and</strong> other <strong>Processing</strong> graphics functions<br />

in more depth beginning in Chapter 6.<br />

Curly braces<br />

Another important <strong>and</strong> widely used syntactical structural element is the curly brace: { }.<br />

Curly braces, which always work in balanced pairs (an open <strong>and</strong> closed pair), are used to<br />

structure blocks of code. Following are some code examples that show the use of curly<br />

braces.<br />

CODE GRAMMAR 101<br />

61<br />

3

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

Saved successfully!

Ooh no, something went wrong!