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

284<br />

Next, I want to put this material to better use <strong>and</strong> cover just a few more curve functions.<br />

But don’t worry, most of the really difficult stuff is over (at least in this chapter). I won’t<br />

formally be covering interactivity until Chapter 12. However, it can be helpful in trying to<br />

underst<strong>and</strong> curve concepts to be able to play around with the curves, including yanking on<br />

their control points. I’m not going to go into all the interactive theory here, so some of the<br />

code in the upcoming interactive examples may look odd (<strong>and</strong> possibly scary). You can<br />

peek ahead to Chapter 12 if you want to, but I’d suggest just playing with the stuff for now,<br />

<strong>and</strong> get to the learning part a little later. You’re entitled to fool around a bit, in blissful<br />

ignorance.<br />

More curve <strong>and</strong> Bézier variations<br />

The next two examples, shown in Figures 7-32 <strong>and</strong> 7-33, are just variations on a theme.<br />

You’ll eventually use the bezier() function to plot a more ambitious sketch consisting of<br />

a very interactive ellipse, which you’ll be able to mess around with in real time. Hopefully<br />

this example will reveal some of the creative potential of having to deal with curve complexity.<br />

First, however, I’ll look at two more functions: bezierVertex() <strong>and</strong> curveVertex().<br />

These functions are really just alternative forms of the bezier() <strong>and</strong> curve() functions.<br />

The following example plots three spirals using the bezier() <strong>and</strong> bezierVertex() functions.<br />

Again, I’ve added extra code to render the control h<strong>and</strong>les to show how their placement<br />

affects the spiral. I didn’t bother to render the anchor points in this example, <strong>and</strong> I<br />

also doubled up the line() <strong>and</strong> ellipse() calls to save a few trees.<br />

// bezier() vs. bezierVertex()<br />

size(650, 225);<br />

background(255);<br />

rectMode(CENTER);<br />

strokeWeight(2);<br />

//bezier() - no fill<br />

noFill();<br />

bezier(50, 50, 92, 15, 134, 15, 175, 50);<br />

bezier(175, 50, 215, 92, 215, 134, 175, 175);<br />

bezier(175, 175, 135, 205, 105, 205, 75, 175);<br />

bezier(75, 175, 50, 145, 50, 105, 75, 75);<br />

bezier(75, 75, 100, 54, 125, 54, 150, 75);<br />

bezier(150, 75, 175, 100, 175, 125, 150, 150);<br />

bezier(150, 150, 134, 160, 118, 160, 100, 150);<br />

bezier(100, 150, 92, 140, 92, 130, 100, 115);<br />

//lines connecting anchor points to control h<strong>and</strong>les<br />

strokeWeight(1);<br />

line(50, 50, 92, 15); line(134, 15, 175, 50);<br />

line(175, 50, 215, 92); line(215, 134, 175, 175);<br />

line(175, 175, 135, 205); line(105, 205, 75, 175);<br />

line(75, 175, 50, 145); line(50, 105, 75, 75);<br />

line(75, 75, 100, 54); line(125, 54, 150, 75);<br />

line(150, 75, 175, 100); line(175, 125, 150, 150);<br />

line(150, 150, 134, 160); line(118, 160, 100, 150);<br />

line(100, 150, 92, 140); line(92, 130, 100, 115);

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

Saved successfully!

Ooh no, something went wrong!