beginShape method
Begins recording a custom shape, defined by various types of vertices.
Using the beginShape()
and endShape()
functions allow creating more
complex forms. beginShape()
begins recording vertices for a shape and
endShape()
stops recording. The value of the kind parameter tells it
which types of shapes to create from the provided vertices. With no mode
specified, the shape can be any irregular polygon. The parameters available
for beginShape()
are ShapeMode.points
, ShapeMode.lines
,
ShapeMode.triangles
, ShapeMode.triangleFan
, ShapeMode.triangleStrip
,
ShapeMode.quads
, and ShapeMode.quadStrip
. After calling the beginShape()
function, a series of vertex()
commands must follow. To stop drawing the
shape, call endShape()
. The vertex()
function with two parameters
specifies a position in 2D and the vertex()
function with three
parameters specifies a position in 3D. Each shape will be outlined with
the current stroke color and filled with the fill color.
Transformations such as translate()
, rotate()
, and scale()
do not
work within beginShape()
. It is also not possible to use other shapes,
such as ellipse()
or rect()
within beginShape()
.
Implementation
void beginShape([ShapeMode? mode]) {
if (_shape != null) {
throw Exception("A shape is already started. Can't start another one.");
}
_shape = _Shape(mode);
}