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.

coordinates of the line. For example, to draw a 2D line across the screen, you pass the initial<br />

point’s coordinate, (x1, y1), <strong>and</strong> the endpoint’s coordinate, (x2, y2), to the line(x1,<br />

y1, x2, y2) function. Figure 6-21 shows the output.<br />

size(500, 300);<br />

background(255);<br />

line(0, height/2, width, height/2);<br />

Figure 6-21. Drawing a 2D line with <strong>Processing</strong>’s line()<br />

function<br />

If you were using one of the 3D rendering options (P3D or OPENGL), you could pass in a<br />

third coordinate, referencing the z-axis. If you run the next example, you’ll notice that the<br />

line doesn’t appear to reach the end of the display, as it did in the last example. This<br />

is because the line is stretching back 300 pixels into virtual space, <strong>and</strong> the P3D renderer is<br />

simulating perspective, which causes things to converge <strong>and</strong> decrease in scale (visually of<br />

course) as they recede into space (see Figure 6-22).<br />

size(500, 300, P3D);<br />

background(255);<br />

// line(x1, y1, z1, x2, y2, z2);<br />

line(0, height/2, 0, width, height/2, -300);<br />

Figure 6-22. Drawing a 3D line with <strong>Processing</strong>’s line()<br />

function<br />

LINES<br />

197<br />

6

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

Saved successfully!

Ooh no, something went wrong!