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.

As you might suspect, anti-aliasing techniques can dramatically impact performance, as<br />

the anti-aliasing calculations take time. <strong>Processing</strong> therefore has two functions: smooth()<br />

<strong>and</strong> noSmooth(). The first turns anti-aliasing on <strong>and</strong> the second turns it off. Anti-aliasing is<br />

off by default in <strong>Processing</strong>. This simple example illustrates the visual difference between<br />

aliasing <strong>and</strong> anti-aliasing in <strong>Processing</strong>; the ellipse on the left of Figure 6-33, using the<br />

default rendering state, is aliased, <strong>and</strong> the ellipse on the right is anti-aliased using<br />

<strong>Processing</strong>’s smooth() function.<br />

size(430, 220);<br />

strokeWeight(2);<br />

ellipseMode(CORNER);<br />

//aliased<br />

ellipse(10, 10, 200, 200);<br />

smooth();<br />

//anti-aliased<br />

ellipse(220, 10, 200, 200);<br />

Figure 6-33. Anti-aliasing example<br />

Please note that calling smooth() can slightly reduce the stroke weight of fine lines. This<br />

can become a factor when you specify small stroke weights. Type in <strong>Processing</strong> utilizes its<br />

own anti-aliasing procedure, so calling smooth() will have no impact on the type’s edges.<br />

To specify anti-aliasing with type, you need to either specify the smooth parameter when<br />

calling the createFont() function, or go to Tools ➤ Create Font <strong>and</strong> select the Smooth<br />

option. Type is always anti-aliased in OS X.<br />

Returning to the Point Recorder/Plotter sketch, I want to give one further example illustrating<br />

another cool feature of using this record/plot approach. Since the point data is<br />

recorded in the xy[][] array <strong>and</strong> then plotted to the screen, I can manipulate or utilize<br />

the point information in the middle of the plotting. The best way to h<strong>and</strong>le this is to create<br />

another simple function that I can pass the point data to for further processing. You can<br />

think of this process like an assembly line, where, for example, a mechanical arm moves a<br />

component down the line, while other machines paint, weld, <strong>and</strong> bend it. In the next<br />

example, as the points are processed in the makeRect() function, they get sent to the<br />

scribble() function, which creates scribbly lines between the points. See Figure 6-34 for<br />

the screen output of this example.<br />

LINES<br />

215<br />

6

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

Saved successfully!

Ooh no, something went wrong!