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

708<br />

Time & Date<br />

Time & Date is the last subsection of the Input section of the API. The functions second(),<br />

minute(), hour(), day(), month(), <strong>and</strong> year() return a component of the time, based off<br />

your system clock. The function millis() tells you how long, in milliseconds (thous<strong>and</strong>ths<br />

of a second), your sketch has been running since you started it. Here’s an analog clock<br />

example (see Figure A-10):<br />

/* Analog Clock<br />

Ira Greenberg, October 9, 2006 */<br />

PFont font;<br />

float x, y, r = 100;<br />

float textH = 12;<br />

void setup(){<br />

size(400, 400);<br />

font = createFont("Arial", textH);<br />

textFont(font);<br />

x = width/2;<br />

y = height/2;<br />

smooth();<br />

}<br />

void draw(){<br />

background(75);<br />

drawClock();<br />

}<br />

void drawClock(){<br />

float px, py, angle = -60;<br />

fill(200);<br />

strokeWeight(4);<br />

ellipse(x, y, r*2, r*2);<br />

for (int i=1; i

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

Saved successfully!

Ooh no, something went wrong!