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

128<br />

Notice that the acceleration curve is concave, like the front of a spoon, while the shape of<br />

the deceleration curve is convex. As you look at the figures, think about how much distance<br />

is being covered over what time period. Is distance increasing more rapidly than<br />

time or vice versa, <strong>and</strong> is the rate of change constant, increasing, or decreasing at different<br />

parts of the curve? Is the curve smooth <strong>and</strong> continuous? The graph shows smooth<br />

acceleration <strong>and</strong> deceleration beginning at point (0, 0), meaning that no time or distance<br />

have elapsed.<br />

In Figures 4-8 <strong>and</strong> 4-9, I divided each of the curves into four straight segments, between<br />

the white points. These straight segments, approximating the curve, are called secant lines.<br />

By looking at the slope of these lines, labeled m1 through m4, you can predict how the<br />

rate of speed is changing in the graphs. It is also possible to more precisely calculate<br />

the slope of each of these secant lines by using the x <strong>and</strong> y components of the points at<br />

the ends of each of the secant lines <strong>and</strong> dividing the change in the two y components<br />

(∆ y) by the change in the two x components (∆ x). For example, to calculate the slope of<br />

the first secant line (m1) in the deceleration curve, you can do the following:<br />

m1 = ∆ y / ∆ x<br />

m1 = 30 – 0 / 1 – 0<br />

m1 = 30<br />

If you take the time to calculate the remaining slopes of m2, m3, <strong>and</strong> m4, you’ll get 10, 5,<br />

<strong>and</strong> 3.33, respectively. Since this is a deceleration curve, it makes sense that the slopes of<br />

the secant lines decrease over time. (Of course, it’s a lot less work to simply guess how the<br />

rate of change is affected based on how vertical the secant lines are.)<br />

It is a little confusing thinking about rate of change vs. speed. Speed is the rate of motion,<br />

which is simpler to think about. Speed is simply distance divided by time. If I move a rectangle<br />

30 pixels in 3 seconds, the rectangle is moving 10 pixel per second (pps); that’s its<br />

speed. For example, the following simple <strong>Processing</strong> sketch moves a rectangle across the<br />

screen at approximately 30 pps:<br />

//linear motion<br />

int w = 20;<br />

int h = 10;<br />

int x = 0;<br />

int y;<br />

void setup(){<br />

size(400, 400);<br />

y = height/2;<br />

frameRate(30);<br />

}<br />

void draw(){<br />

background(255);<br />

rect(x++, y, w, h);<br />

}

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

Saved successfully!

Ooh no, something went wrong!