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

60<br />

Congratulations! OK, so maybe it wasn’t a huge improvement to “Hello World,” but you<br />

got to make a pretty, blue circle. Let’s look at the program line by line.<br />

/* <strong>and</strong> */ are block comment tags, used to comment out multiple lines of information so<br />

that it is ignored by the compiler. // can be used to comment out a single line. It is typical<br />

at the top of a program to put some info about what your program does, who created it,<br />

the creation date, <strong>and</strong> any other special notes. This is not required, but most people put<br />

something up there. In fact, some people put a lot of stuff up there, including specific<br />

code usage rights. How much you include up there doesn’t really matter because it won’t<br />

affect how your program functions. However, novellas, mission statements, <strong>and</strong> manifestos<br />

should probably be put other places. Here are some more examples of comments:<br />

// this is a valid comment<br />

/* this is a valid comment */<br />

/*<br />

this is a valid comment<br />

*/<br />

// this<br />

// is also<br />

// a valid<br />

// comment<br />

After the comments, I skipped a line. This is called whitespace. Whitespace in <strong>Processing</strong><br />

<strong>and</strong> Java is disregarded, as it is in many other programming languages. You can put as much<br />

whitespace as you like to help you visually organize your code. The next line in the program,<br />

size(200, 200); is a function call (I spoke about functions in Chapter 2—functions<br />

are reusable blocks of code that you call when you need them). You know this because of<br />

the parentheses after the word size. As stated in Chapter 2, a function call . . . well . . .<br />

calls a function—in this case, a function named size. The numbers within the parentheses<br />

are called arguments—things that are passed to the function, which the function expects<br />

to receive <strong>and</strong> makes use of. In this case, the numbers represent the width <strong>and</strong> height of<br />

the sketch window. When more than one argument is passed to a function, as in<br />

size(200, 200);, commas are used to separate the individual arguments. There is no limit<br />

to the number of arguments you can pass to a function, as long as the function has the<br />

same number of parameters to receive the arguments. In addition, they must be sent to<br />

the function in the same order that the function expects to receive them. In the case of<br />

the function calls in the Hello Earth example, the functions I called are all built into the<br />

<strong>Processing</strong> language, <strong>and</strong> thus you can’t see the actual function definitions. I’ll be<br />

discussing functions in much greater detail later on in this chapter. For now, let’s keep<br />

moving.<br />

At the end of the size(200, 200); call, you should notice a semicolon. Semicolons in<br />

coding are like periods in normal human language. They let the compiler know where the<br />

end of the statement is. A statement is simply a comm<strong>and</strong> to the program to do something.<br />

In <strong>Processing</strong>, failure to include a semicolon results in a compiler error—an error

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

Saved successfully!

Ooh no, something went wrong!