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.

plotted, the vertices are connected with straight lines, <strong>and</strong> the space between the lines is<br />

filled in with the RGB color (R = 0, G = 0, <strong>and</strong> B = 255)—which makes blue. So far this is<br />

pretty simple, right?<br />

If the rectangle is 10 pixels by 10 pixels, then you have 100 pixels altogether (10 ✕ 10). You<br />

can also think about the rectangle as a table of 10 rows of pixels by 10 columns of pixels.<br />

The BufferedImage class h<strong>and</strong>les these types of storage issues internally, which can get<br />

complex, as each pixel is made up of other components. In addition, the BufferedImage<br />

class maintains an internal model of an image, rather than generating an actual screen<br />

image—which is the work of a Graphics object or graphics context, which I’ll discuss later<br />

on. The word “Buffer” within BufferedImage refers to a pixel buffer, which simply means<br />

an internal storage structure for the pixel data. Computer graphics relies on these types of<br />

buffers to efficiently manage the vast amounts of data involved in graphics <strong>and</strong> animation.<br />

There are numerous ways to store pixel data, based on different sample <strong>and</strong> color models.<br />

For example, pixel data can be stored in an internal table structure, with rows <strong>and</strong> columns<br />

that are essentially equivalent to the image’s pixel structure on the screen; while another<br />

internal buffer can hold the pixel data organized by color. Some of the composite helper<br />

classes connected to the BufferedImage class organize pixel data into other structural<br />

units such as samples, b<strong>and</strong>s, banks, <strong>and</strong> rasters, which add flexibility <strong>and</strong> power to the<br />

class, but also contribute to its complexity—it’s a good thing <strong>Processing</strong> internally h<strong>and</strong>les<br />

most of this stuff for us. Next, let’s go in a little deeper <strong>and</strong> explore the pixel.<br />

The pixel<br />

COMPUTER GRAPHICS, THE FUN, EASY WAY<br />

Pixel, short for picture element, is the term used to describe the smallest unit of a digital<br />

image. Essentially, pixels are just little blocks of colors that, when grouped together en<br />

masse, form images. Each pixel on the screen has a range of possible colors dependent<br />

upon the color depth of the monitor, which is a function of both the monitor <strong>and</strong> the<br />

available memory on the computer’s video card. Modern monitors <strong>and</strong> video cards are all<br />

generally capable of displaying 24-bit color depth—meaning that each pixel on the screen<br />

can utilize 24 bits of information. Remember, a bit is a unit of measure, representing the<br />

smallest unit of memory on a computer (either 0 or 1), <strong>and</strong> there are 8 bits in 1 byte. Each<br />

pixel on a color display is composed of three components, representing the colors red,<br />

green, <strong>and</strong> blue (RGB). Thus, a 24-bit pixel has 8 bits devoted to each of its three component<br />

colors. Since 8 bits is kind of meaningless to most of us as a unit of measure, let’s<br />

convert 8 bits, which lives in base 2 (binary system) to our familiar base 10 (decimal system).<br />

To convert base 2 to base 10, you take the base (also called the radix), which in this<br />

case is 2 (only 2 choices for bits—0 or 1), <strong>and</strong> raise it to the power of the number of places<br />

(number of bits) in your number, in this case 8. Raising 2 to the 8th power (2 8 ) gives you<br />

256. So each of the color components in the pixel then has a range of 256 different values,<br />

representing the total number of combinations of zeros <strong>and</strong> ones in an 8-digit number.<br />

In the preceding <strong>Processing</strong> function call fill(0, 0, 255);, for each of the arguments (R,<br />

G, B) you can set a number between 0 <strong>and</strong> 255 (the 0 counts as a value—that’s why it only<br />

goes up to 255, not 256—but the range of values, or the domain of each component, is<br />

256). If you take the three different components (R, G, <strong>and</strong> B) <strong>and</strong> multiply each of their<br />

domains together (256 ✕ 256 ✕ 256), you get 16,777,216 possible colors. Another way of<br />

thinking about this (<strong>and</strong> actually closer to how the computer thinks about it) is that a<br />

113<br />

4

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

Saved successfully!

Ooh no, something went wrong!