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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

502<br />

Figure 11-10. Ravenous Ellipse II sketch<br />

Now the predatory motion is smoother <strong>and</strong> much more natural. And all I added were the<br />

two easing statements (besides of course declaring the easing variable at the top of the<br />

sketch):<br />

// cause the predator to decelerate<br />

deltaX *= easing;<br />

deltaY *= easing;<br />

Let’s replace the ravenous ellipse with an even more ravenous triangle (shown in<br />

Figure 11-11). The triangle will not only follow the mouse, but remain oriented in a certain<br />

direction so that it can attack with its mouth (you’ll have to take my word that this triangle<br />

does indeed have a mouth). I’ll create the triangle <strong>and</strong> its orientation using some trig.<br />

// Ravenous Triangle I<br />

float predCntrX, predCntrY;<br />

float predX[] = new float[3];<br />

float predY[] = new float[3];<br />

float predLen = 8.0;<br />

float predAng, predRot;<br />

float easing = .05;

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

Saved successfully!

Ooh no, something went wrong!