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.

I included one last example (shown in Figure 7-37) on how to create an elliptical spline plot<br />

using shape() <strong>and</strong> shapeVertex(). I also included a more generalized spline ellipse–<br />

creation function. Notice how the curveTightness settings affect the different curves,<br />

creating interesting path details. Similarly to the bezier() example, I initially populate the<br />

coordinate arrays with ellipse point data, using some trig expressions. However, unlike<br />

bezier(), I’m not burdened with anchor <strong>and</strong> control points. When drawing the closed<br />

curves, I followed the control point order I covered earlier in the chapter. This is not terribly<br />

intuitive, so it might help to mess with the node order in the curve() functions a little<br />

to see how it affects the curve. I implemented the first ellipse using curve(), <strong>and</strong> the second<br />

using curveVertex(). I’m not sure which is easier—probably curveVertex(), since it<br />

uses a shorter parameter list. The problem with the initial ellipse plots is that they are<br />

hard-coded for four points <strong>and</strong> can’t easily be customized. Thus, I created a more general<br />

spline ellipse function as well, allowing you to control the number of points, as well as the<br />

x <strong>and</strong> y position, radius, <strong>and</strong> curve tightness, among other properties. The function is used<br />

to generate the two inner curves. This modular approach will be looked at in more depth<br />

in the next chapter, as you begin to apply some object-oriented approaches to the examples.<br />

/*<br />

Curve Ellipse<br />

Ira Greenberg, December 20, 2005<br />

revised November 15, 2006<br />

*/<br />

float radius = 165;<br />

float angle = 0;<br />

//outer circle<br />

float[]cx = new float[4];<br />

float[]cy = new float[4];<br />

//middle circle<br />

float[]cx2 = new float[4];<br />

float[]cy2 = new float[4];<br />

void setup(){<br />

size(400, 400);<br />

background(255);<br />

strokeWeight(1.5);<br />

smooth();<br />

for (int i =0; i

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

Saved successfully!

Ooh no, something went wrong!