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.

Figure 6-19. Yin Yang Fade sketch, variation 2<br />

Try running this code a couple times to see how it changes. The shift from black to white,<br />

in both the grid <strong>and</strong> razor-tooth pattern, creates an interesting example of sfumato (or<br />

smoke), giving the image a sense of atmosphere. You’ll notice in the code that I reversed<br />

the order of the grid <strong>and</strong> the razor-tooth pattern code blocks. Putting the grid down first<br />

created more clarity in the final image. Try reversing the blocks of code to see the difference.<br />

In the next examples, you’ll explore some other ways of generating lines in<br />

<strong>Processing</strong>.<br />

Creating lines with pixels<br />

Besides using <strong>Processing</strong>’s point() function to generate lines, you can also directly set the<br />

value of a line of pixels. In the next example, a PImage object is created, <strong>and</strong> the pixels<br />

along the horizontal, vertical, <strong>and</strong> diagonal center axes are set to black (see Figure 6-20).<br />

Please note that the PImage object is not automatically rendered to the screen; to do so,<br />

you need to explicitly call the image() function (see the last line of code in the example).<br />

size(500, 300);<br />

background(255);<br />

// used by diagonal lines<br />

float slope = float(height)/float(width);<br />

PImage img = createImage(width, height, RGB);<br />

color c = color(0, 0, 0);<br />

//horizontal line<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!