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

486<br />

One of the nice things about waiting until Chapter 11 to cover motion is that I’ve had time<br />

to properly introduce <strong>and</strong> reinforce basic coding principles <strong>and</strong> structures, allowing you to<br />

focus on more creative applications using these structures. Thus, I’m going to assume you<br />

underst<strong>and</strong> the code in the last example. If, however, the array structures still seem confusing,<br />

I recommend a quick review of the section on arrays, in Chapter 3. I can improve<br />

this last sketch by alternating the y position of the rectangles over time <strong>and</strong> using variable<br />

speed (shown in Figure 11-3):<br />

// Painting Stripes II<br />

int shapes = 200;<br />

float[]speedX = new float[shapes];<br />

float[]speedY = new float[shapes];<br />

float[]x = new float[shapes];<br />

float[]y = new float[shapes];<br />

float[]w = new float[shapes];<br />

float[]h = new float[shapes];<br />

color[]colors = new color[shapes];<br />

void setup(){<br />

size(400, 400);<br />

frameRate(30);<br />

noStroke();<br />

// fill arrays will r<strong>and</strong>om values<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!