06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

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.

Text 323<br />

Exercise 17-10: Create a sketch that starts with characters randomly scattered (and rotated).<br />

Have them slowly move back <strong>to</strong>ward their “ home ” location. Use an object-oriented approach<br />

as seen in Example 17-6. 1<br />

One way <strong>to</strong> solve this is <strong>to</strong> use interpolation. Interpolation refers <strong>to</strong> the process of<br />

calculating values in between two given pieces of data. In this exercise, we want <strong>to</strong> know<br />

the in-between x locations (and y locations) from the random starting point <strong>to</strong> the target<br />

location in the String . One interpolation method is <strong>to</strong> simply take the average. Th ink of it<br />

as walking <strong>to</strong> a wall by always taking a step halfway.<br />

x = (x + targetX) /2;<br />

y = (y + targetY) /2;<br />

Another possibility is <strong>to</strong> simply go 10% of the way there.<br />

x = 0.9*x + 0.l*targetX;<br />

y = 0.9*y + 0.l*targetY;<br />

<strong>Processing</strong> ’s lerp( ) function will do interpolation for you. Visit the reference page for more<br />

information: http://processing.org/reference/lerp_.html.<br />

Consider making your sketch interactive. Can you push the letters around using the mouse?<br />

1 Th e origins of this exercise can be traced back <strong>to</strong> John Maeda’s 1995 work: Flying Letters .

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

Saved successfully!

Ooh no, something went wrong!