This page is optimized for mobile devices, if you would prefer the desktop version just
click here
Collections of triangles
A set of triangles can be defined, similarly to what we did for points and segments, by the delimitersbeginShape()
and
endShape()
. Between
them, the vertices of the triangles are listed by calls to thefunction
vertex()
. By the invocation
beginShape(TRIANGLES)
the vertices are taken in
triples, each defining a triangle, while the invocation
beginShape(TRIANGLE_STRIP)
takes the vertices one
after the other to define a strip mad of triangular facets. Ifthe
vertex()
has three arguments, the vertices
are located in the 3D space and the corresponding trianglesidentify planar surfaces in space.
Quadrilaterals
Rectangles are defined, in Processing, by the functionrect()
of four parameters, where the first couple
specifies, by default, the position in the the 2D plane of thetop-left corner, and the third and fourth parameters specify
the width and height, respectively. The meaning of the firstcouple of parameters can be changed with the function
rectMode()
:
rectMode(CORNER)
gives
the default positioning;
rectMode(CENTER)
gives
the positioning of the center of the rectangle at thespecified point; with the
rectMode(CORNERS)
the
four parameters are interpreted as the coordinates of thetop-left and bottom-right vertices, respectively. A generic
quadrilateral is defined by the coordinates of its fourvertices, passed as parameters to the function
quad()
. It is important to notice that in 3D,
while a triangle stays planar in any case, a quadruple ofpoints does not necessarily lay on a plane. Viceversa, the
quadrilaterals that are defined by 3D roto-translations ofquadruples of 2D vertices, remain planar. Processing allows
only eight parameters to be passed to
quad()
,
thus forcing the definition of a quadrilateral as a quadrupleof vertices in 2D.
Collections of quadrilaterals
A set of quadrilaterals can be defined, similarly to what we saw for triangles, by the delimitersbeginShape()
and
endShape()
. Between
them, vertices are listed by calls to the function
vertex()
. By using the invocation
beginShape(QUADS)
the vertices are taken in
quadruples, each identifying a quadrilateral, while theinvocation
beginShape(QUAD_STRIP)
takes the
vertices one after the other to define a strip mad ofquadrilateral facets. If the
vertex()
have three
parameters, the planarity of the resulting faces is notensured, and the resulting rendering can be misleading. For
instance, by running the code
size(200,200,P3D);
lights();beginShape(QUADS);
vertex(20,31, 33);vertex(80, 40, 38);
vertex(75, 88, 50);vertex(49, 85, 74);
endShape();
we realize that the quadrilateral is rendered as the
juxtaposition of two triangles belonging to differentplanes.
Polygons
A generic polygon is defined as a set of vertices, and it has a surface that can becolored. In Processing the vertices are listed within a couplebeginShape(POLYGON);
-
endShape();
Actually, the polygon has to be intended in a generalized
sense, as it is possible to use the
bezierVertex()
and
curveVertex()
to
specify curved profiles. For instance, the reader may try todraw the moon:
fill(246, 168, 20);
beginShape(POLYGON);vertex(30, 20);
bezierVertex(80, 10, 80, 75, 30, 75);bezierVertex(50, 70, 60, 25, 30, 20);
endShape();
Read also:
OpenStax, Media processing in processing. OpenStax CNX. Nov 10, 2010 Download for free at http://cnx.org/content/col10268/1.14
Google Play and the Google Play logo are trademarks of Google Inc.