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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

64<br />

Literals<br />

As you will learn in the next section, a variable is something that can mean different things<br />

in different parts of the program. However, a literal is simply an explicit number or string<br />

constant (words or characters) used in programs. Here are some examples:<br />

"Sophie"<br />

25<br />

10346<br />

"abc"<br />

Note that string literals are enclosed in quotes (usually double quotes) <strong>and</strong> numeric literals<br />

are not. In some cases, if you need a string within a string, you surround the inner string<br />

with single quotes. Here’s an example:<br />

"One of Shakespeare's most famous lines 'to be or not to be'<br />

is in Hamlet"<br />

Here’s a sketch that outputs some literal values:<br />

String announceDate = "I'm writing this on: ";<br />

String currentMonth = "March ";<br />

int currentDay = 5;<br />

String currentDayName = "Sunday";<br />

int currentYear = 2006;<br />

String comma = ", ";<br />

print(announceDate);<br />

println(currentDayName);<br />

print(currentMonth);<br />

print(currentDay);<br />

print(comma);<br />

println(currentYear);<br />

This sketch will output the following:<br />

I'm writing this on: Sunday<br />

March 5, 2006<br />

Notice how I used the print() <strong>and</strong> println() statements to help me format the outputted<br />

lines combining the literals.

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

Saved successfully!

Ooh no, something went wrong!