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

228<br />

called theta, <strong>and</strong> the radius of the circle. However, the unit circle lives in a polar coordinate<br />

system, not the happy Cartesian system we use on a computer screen. Thus, you also<br />

need to convert from the polar to the Cartesian coordinate system to get your x <strong>and</strong> y<br />

coordinates. The two general statements to do all of this are as follows:<br />

x coordinate = x position of the center of circle + cos(angle of rotation in radians) * radius<br />

y coordinate = y position of the center of circle + sin(angle of rotation in radians) * radius<br />

Returning to the two trig expressions in the triangle sketch, I used the center of the display<br />

window as the center point of the unit circle, which will also be the center point of the<br />

triangle. The function radians(angle) converts from degrees to radians; the actual conversion<br />

expression is (angle in radians) = (angle in degrees) * pi / 180, which is what the<br />

radians() function encapsulates. Lastly, I used width/2.5 as the radius.<br />

<strong>Processing</strong> includes a function that lets you control how lines join together. Earlier, you<br />

looked at the function strokeCap(), which controls the end caps of lines. The function<br />

strokeJoin() controls the way the end caps come together to form joints. There are three<br />

different join options, in the form of integer arguments (constants): MITER, which is the<br />

default; BEVEL; <strong>and</strong> ROUND. This next example uses the triangle code to show the difference<br />

in the respective join options (see Figure 6-39 for the output).<br />

//create 3 triangles<br />

size(600, 200);<br />

background(0);<br />

stroke(255);<br />

noFill();<br />

strokeWeight(10);<br />

smooth();<br />

float x = 0, y = 0;<br />

// sets initial shape rotation<br />

float angle = 30;<br />

// join types<br />

int[]joins = {MITER, BEVEL, ROUND};<br />

for (int j=1; j

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

Saved successfully!

Ooh no, something went wrong!