Py5Shape.get_vertex_code()#

Get the vertex code for a particular vertex code index.

Examples#

example picture for get_vertex_code()
 1SHAPE_VERTEX_CODES = {py5.Py5Shape.BREAK: 'BREAK',
 2                      py5.Py5Shape.VERTEX: 'VERTEX'}
 3
 4
 5def setup():
 6    py5.size(100, 100, py5.P2D)
 7    s = py5.create_shape()
 8    s.begin_shape()
 9    s.vertex(20, 20)
10    s.vertex(80, 20)
11    s.vertex(80, 80)
12    s.vertex(20, 80)
13    s.begin_contour()
14    s.vertex(40, 40)
15    s.vertex(40, 60)
16    s.vertex(60, 60)
17    s.vertex(60, 40)
18    s.end_contour()
19    s.end_shape(py5.CLOSE)
20    py5.shape(s)
21
22    py5.println(s.get_vertex_count(), s.get_vertex_code_count())  # 8 9
23    # ['VERTEX', 'VERTEX', 'VERTEX', 'VERTEX', 'BREAK', 'VERTEX', 'VERTEX', 'VERTEX', 'VERTEX']
24    py5.println([SHAPE_VERTEX_CODES[s.get_vertex_code(i)]
25          for i in range(s.get_vertex_code_count())])

Description#

Get the vertex code for a particular vertex code index. The vertex codes can be used to inspect a shape’s geometry to determine what kind of vertices it has. Each can be one of BREAK, VERTEX, BEZIER_VERTEX, QUADRATIC_VERTEX or CURVE_VERTEX.

The vertex codes will not necessarily align with the vertices because number of vertex codes may be larger than the number of vertices. This will be the case for shapes that use contours, and therefore contain BREAK codes.

Underlying Processing method: PShape.getVertexCode

Syntax#

get_vertex_code(index: int, /) -> int

Parameters#

  • index: int - vertex code index

Updated on November 12, 2021 11:30:58am UTC