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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Your first program<br />

In most programming books, the first program written is called “Hello World” (see<br />

Figure 3-1). This spectacular program spits back the words “Hello World” to the screen—<br />

yawn! Needless to say, I find this program extremely boring <strong>and</strong> also think it sets the wrong<br />

tone for an entire book on creative coding. I for one need more encouragement <strong>and</strong> inspiration<br />

before attempting to learn something as scary <strong>and</strong> potentially boring as programming.<br />

Thus in breaking with tradition, which this book is all about, the first program you<br />

write will be entitled “Hello Earth.” Here it is:<br />

/*<br />

Program Title: "Hello Earth"<br />

Program Description: Blue circle on black background<br />

By Ira Greenberg, August 5, 2005<br />

Comments: Our first <strong>Processing</strong> program- yippee!<br />

*/<br />

size(200, 200);<br />

background(0);<br />

// keep stroke from showing up around circle<br />

noStroke();<br />

fill(80, 220, 255);<br />

ellipse(100, 100, 100, 100);<br />

print("Hello Earth!");<br />

If you haven’t done so yet, download <strong>Processing</strong> from http://processing.org/download/<br />

index.html. I recommend selecting the st<strong>and</strong>ard download option. The installer will<br />

create a <strong>Processing</strong> directory. Within this directory, you’ll find the <strong>Processing</strong> application<br />

icon. Launch it, <strong>and</strong> type the “Hello Earth” sketch code into <strong>Processing</strong>’s text editor (the<br />

big, white area in the middle of the application); then press the right-facing arrow in the<br />

circle, at the top of the application.<br />

Figure 3-1. Your first Hello Earth program<br />

CODE GRAMMAR 101<br />

59<br />

3

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

Saved successfully!

Ooh no, something went wrong!