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.

a piece of paper <strong>and</strong> do a little more involved math to properly solve the problem. Being<br />

impetuous, manic, <strong>and</strong> very sleep-deprived, I just kept furiously hacking at the code—hoping<br />

for some quick (magical) fix; It wasn’t going too well, <strong>and</strong> I actually went so far as to<br />

find a pencil. Eventually something emerged, but it didn’t look very much like a serpent.<br />

Instead, I found a strange, smoky, self-organizing blob (see Figure 4-13). In the end, I think<br />

I got something more interesting than I originally planned for, <strong>and</strong> I learned something in<br />

the process—so embrace the chaos! The code to this sketch, entitled Puff, follows. This is<br />

not simple code, but it is an excellent demonstration of the expressive power of trig.<br />

/* puff<br />

Ira Greenberg, October 22, 2005 */<br />

// for puff head<br />

float headX;<br />

float headY;<br />

float speedX = .7;<br />

float speedY = .9;<br />

// for puff body<br />

int cells = 2000;<br />

float[]px= new float[cells];<br />

float[]py= new float[cells];<br />

float[]radiiX = new float[cells];<br />

float[]radiiY = new float[cells];<br />

float[]angle = new float[cells];<br />

float[]frequency = new float[cells];<br />

float[]cellRadius = new float[cells];<br />

void setup(){<br />

size(400, 400);<br />

// begin in the center<br />

headX = width/2;<br />

headY = height/2;<br />

//fill body arrays<br />

for (int i=0; i< cells; i++){<br />

radiiX[i] = r<strong>and</strong>om(-7, 7);<br />

radiiY[i] = r<strong>and</strong>om(-4, 4);<br />

frequency[i]= r<strong>and</strong>om(-9, 9);<br />

cellRadius[i] = r<strong>and</strong>om(16, 40);<br />

}<br />

frameRate(30);<br />

}<br />

void draw(){<br />

background(0);<br />

noStroke();<br />

fill(255, 255, 255, 5);<br />

COMPUTER GRAPHICS, THE FUN, EASY WAY<br />

137<br />

4

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

Saved successfully!

Ooh no, something went wrong!