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.

Geometry<br />

Like algebra, geometry dates way back to ancient Egypt <strong>and</strong> Babylonia (2000 to 500 BC),<br />

where knowledge of geometry was demonstrated through building <strong>and</strong> development projects.<br />

However, it was Greek influence, beginning with Thales <strong>and</strong> Pythagoras in around 600<br />

BC, through to Archimedes in around 200 BC, that gave us what we think of as Euclidian<br />

geometry today. Of all the Greeks, it was Euclid of Alex<strong>and</strong>ria, in around 300 BC, who<br />

would leave the most lasting mark on Greek geometry with his famous 13-book treatise,<br />

The Elements of Geometry. This treatise formalized Greek thought on geometry up to that<br />

point, <strong>and</strong> is even considered by some to be the first textbook ever written. It is certainly<br />

one of the most important <strong>and</strong> influential books ever written on mathematics, with versions<br />

of it still in print—over 2,500 years after it was written—that would be a lot of royalties<br />

for Euclid!<br />

The word geometry comes from the Greek words for earth <strong>and</strong> measure, <strong>and</strong> suggests its<br />

original use in building, surveying, astronomy, <strong>and</strong> other real-world applications. Geometry<br />

was introduced to Europe during the early Renaissance, <strong>and</strong> its influence is obvious <strong>and</strong><br />

ubiquitous, especially in Renaissance architecture <strong>and</strong> the visual arts. However, with regard<br />

to computer graphics, the major development in geometry didn’t occur until the 17th century,<br />

with the advent of analytical or coordinate geometry, developed by René Descartes<br />

<strong>and</strong> Pierre de Fermat. Analytical geometry utilizes the Cartesian coordinate system (also<br />

developed by Descartes) as a system to study geometric curves <strong>and</strong> shapes plotted utilizing<br />

algebraic equations, which is precisely what is done in computer graphics. (Thankfully,<br />

most of the math is actually done behind the scenes for us.)<br />

Points<br />

The point is the most basic geometric element we deal with. A point has 0 dimensions;<br />

although in <strong>Processing</strong>, you do see a 1 pixel by 1 pixel output to the screen when you write<br />

the following comm<strong>and</strong> (making this technically a 1-pixel-long line—but we’ll let it pass).<br />

point(x, y);<br />

Points, as data structures, are primarily used to store coordinate locations for plotting<br />

curves <strong>and</strong> shapes. Java has some convenient data structures, or classes, for this very purpose,<br />

such as the aptly named Point class. Remember, in <strong>Processing</strong>, you have the option<br />

of using Java classes as you see fit.<br />

Lines<br />

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

Lines occupy one dimension, as they have length, but no width. Lines can be expressed<br />

algebraically with the expression y = mx + b.<br />

This equation for a line is referred to as the slope-intercept form, where m is the slope of<br />

the line <strong>and</strong> b is the y-intercept (the place where the line intercepts the y-axis). x <strong>and</strong> y are<br />

the two components of any point on the line. Slope is an important property of a line or<br />

curve in math <strong>and</strong> computer graphics, <strong>and</strong> often relates graphically to motion <strong>and</strong> acceleration.<br />

For example, the graph of the line in Figure 4-5 shows an object moving at a constant<br />

rate. The vertical axis of the graph is distance, <strong>and</strong> the horizontal axis is time. The<br />

slope of the line can be found by looking at the change in y (∆ y) over the change in x<br />

(∆ x) at any two points on the graph. People commonly refer to the slope as rise over run.<br />

123<br />

4

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

Saved successfully!

Ooh no, something went wrong!