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

406<br />

I’m sure most of you recognized the output as the classic color wheel, composed of the<br />

three primaries (red, yellow, <strong>and</strong> blue), the three secondaries (green, purple, <strong>and</strong> orange)<br />

<strong>and</strong> the six tertiaries (yellow-orange, red-orange, red-purple, blue-purple, blue-green, <strong>and</strong><br />

yellow-green). The two wheels (one showing shades of the colors <strong>and</strong> the other showing<br />

tints) represent color relationships as perceived off a reflective colored surface, such as a<br />

painting. This color model is referred to as subtractive. When the full spectrum of colors is<br />

mixed together in the subtractive model, we get a dark, neutral color that approaches<br />

black. In contrast, the colors we perceive on a computer monitor, through projected light,<br />

are considered additive. These colors, when mixed together, create white light. In addition,<br />

the primaries in the additive model are red, green, <strong>and</strong> blue, as opposed to red, yellow,<br />

<strong>and</strong> blue, as in the subtractive model.<br />

The preceding sketch uses the arc() function to create a series of circles (composed of<br />

pie wedges) that overlap one another. The overlapping circles get progressively smaller,<br />

while the value of the color darkens <strong>and</strong> lightens on the left <strong>and</strong> right circles, respectively.<br />

Since the colors are fully opaque, there is no mixing of the overlapping pie wedges—<br />

rather, the shift in value is determined solely by the calculations within the cols[] array.<br />

The array uses <strong>Processing</strong>’s color data type. I create <strong>and</strong> fill the arrays from scratch each<br />

iteration of the loop, using anonymous color objects; they’re anonymous only in the sense<br />

that I’m not assigning each color object to a variable. As a fun problem to try on your own,<br />

try modifying the previous sketch to generate two similar wheels based on the additive<br />

model.<br />

Controlling alpha transparency<br />

Besides the color component properties, you can also specify an alpha component, which<br />

controls the transparency of the color. For grayscale, you pass an optional second argument,<br />

<strong>and</strong> for color you pass an optional fourth argument. Here’s a combined example<br />

that shows both (see Figure 10-4):<br />

// Alpha<br />

size(400, 315);<br />

for (int i=0; i< height; i+=width/15){<br />

float r=r<strong>and</strong>om(255);<br />

float g=r<strong>and</strong>om(255);<br />

float b=r<strong>and</strong>om(255);<br />

for (int j=0, a=255; j

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

Saved successfully!

Ooh no, something went wrong!