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

198<br />

The rest of the examples in this chapter will be 2D. (Drawing in 3D will be discussed later<br />

in the book.) Utilizing the line() function, you can more easily create complex linear<br />

structures than using either the point() or PImage approaches. Aside from specifying the<br />

position <strong>and</strong> length of a line, you can use some of <strong>Processing</strong>’s rendering style functions to<br />

affect the rendering state of the line. Next is a very simple example demonstrating the use<br />

of the strokeWeight() function (see Figure 6-23).<br />

size(500, 300);<br />

background(255);<br />

int step = height/10;<br />

for (int i=step; i< height; i+=step ){<br />

strokeWeight(i*.1);<br />

line(20, i, width-20, i);<br />

}<br />

Figure 6-23. Stroke weight variation example<br />

As the line or stroke increases in weight, the end caps of the line become very prominent.<br />

The default style is ROUND. However, end caps can be set using the strokeCap() function<br />

by passing one of three constants, ROUND, PROJECT, or SQUARE, to the function. I recoded<br />

the last example, changing some of the end caps (see Figure 6-24). Please also note the<br />

strokeCap() function only works with the default JAVA2D rendering mode. If you specify<br />

any of the other modes (P3D, OPENGL, or P2D), this feature will not work.<br />

size(500, 300);<br />

background(255);<br />

int step = height/10;<br />

int[]caps = {ROUND, PROJECT, SQUARE};<br />

int j = 0;<br />

for (int i=step; i2){<br />

j=0;<br />

}<br />

line(20, i, width-20, i);<br />

}

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

Saved successfully!

Ooh no, something went wrong!