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.

Some of the reasons coding graphics gets a reputation for being difficult is the math<br />

involved in dealing with 3D space <strong>and</strong> the low-level algorithms needed to manipulate millions<br />

of pixels in real time. 3D math is somewhat complicated, especially if you don’t have<br />

a basic grounding in linear algebra <strong>and</strong> trigonometry, neither of which are really that complicated,<br />

but are usually purged from most artist’s brains by the time they leave high<br />

school (if it ever got in there in the first place). Because computer monitors are 2D surfaces,<br />

there is a need in 3D to always convert 3D geometry back to a 2D projection, so we<br />

can see it on the screen.<br />

<strong>Computational</strong>ly, graphics requires a fair amount of low-level processing <strong>and</strong> lots of memory<br />

storage. For example, on a monitor with 1920 ✕ 1200 resolution, over 2,300,000 pixels<br />

are redrawn about 70 times per second. Each pixel is made up of three color components<br />

(RGB), giving each of the 2 million–plus pixels a range of 16.7 million different colors.<br />

Once you add the actual calculations needed to generate 2D or 3D geometry, virtual light<br />

sources, textures, special effects, animation, virtual cameras, <strong>and</strong> event processing (user<br />

interaction)—well, you develop a lot of respect for engineers! As computers have gotten<br />

faster <strong>and</strong> memory has gotten cheaper, graphics programming has benefited greatly <strong>and</strong><br />

things have gotten a little simpler, but less is definitely not more when it comes to graphics,<br />

<strong>and</strong> in spite of the technological advances, users continuously dem<strong>and</strong> more from<br />

their games, films, software, <strong>and</strong> personal devices. In this chapter, I am only going to deal<br />

with 2D graphics <strong>and</strong> some basic math. In spite of all the complexity I just mentioned,<br />

<strong>Processing</strong> makes it pretty easy to get started with graphics (<strong>and</strong> of course I’ll continue to<br />

take things slowly). Although this chapter only deals with 2D, everything I cover is applicable<br />

to 3D, which I’ll cover near the end of the book.<br />

Coordinate systems<br />

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

A coordinate system is simply a numbered grid that allows you to locate a point in space.<br />

Two French mathematicians, René Descartes (1596–1650) <strong>and</strong> Pierre de Fermat (1601–1665)<br />

get credited with developing the Cartesian coordinate system; although Descartes gets<br />

most, if not all, of the credit. The Cartesian coordinate system is really just an extension of<br />

a number line. The number line has a 0 position; values to the right of 0 are positive <strong>and</strong><br />

values to the left of 0 are negative—pretty basic stuff. In the coordinate system most of us<br />

remember from math class, there is a horizontal axis, usually referred to as x <strong>and</strong> a vertical<br />

axis, referred to as y. The vertical axis has its own number line, <strong>and</strong> where these two perpendicular<br />

number lines intersect (0, 0) is the origin. In the coordinate system we use in<br />

math, above the y-origin is positive <strong>and</strong> below the y-origin is negative. In computer graphics,<br />

this is often flipped, as it is in <strong>Processing</strong>—above the y-origin is negative <strong>and</strong> below the<br />

y-origin is positive. Figure 4-1 illustrates the coordinate system in <strong>Processing</strong>, in relation to<br />

the monitor. You’ll notice that the origin is at the top-left corner of the coordinate system.<br />

109<br />

4

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

Saved successfully!

Ooh no, something went wrong!