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

692<br />

2D Primitives<br />

Curves<br />

3D Primitives<br />

Attributes<br />

Vertex<br />

2D Primitives<br />

2D primitives are the basic geometric building blocks. They include points, lines, triangles,<br />

rectangles, arcs, <strong>and</strong> ellipses. Shapes like squares <strong>and</strong> circles are just variations on rectangles<br />

<strong>and</strong> ellipses. These functions are incredibly easy to use <strong>and</strong> fun to experiment with. As<br />

you’ll learn eventually, all shapes are really just points, or vertices connected <strong>and</strong> optionally<br />

filled. However, it makes it really convenient to encapsulate this process for the basic<br />

building block shapes into neat functions, like the ones in <strong>Processing</strong>. Here’s a simple<br />

example of a point inside a triangle, inside a rectangle, inside an ellipse (see Figure A-5):<br />

size(200, 200);<br />

background(255);<br />

smooth();<br />

noFill();<br />

point(width/2, height/2);<br />

triangle(40, 160, 100, 40, 160, 160);<br />

rect(40, 40, 120, 120);<br />

ellipse(width/2, height/2, 120, 120);<br />

Figure A-5. <strong>Processing</strong>’s 2D primitive functions

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

Saved successfully!

Ooh no, something went wrong!