Py5Shape.vertex()#

Add a new vertex to a Py5Shape object.

Examples#

example picture for vertex()
1def setup():
2    s = py5.create_shape()
3    s.begin_shape()
4    s.vertex(20, 80)
5    s.vertex(80, 80)
6    s.vertex(50, 20)
7    s.end_shape(py5.CLOSE)
8
9    py5.shape(s)
example picture for vertex()
 1def setup():
 2    py5.size(100, 100, py5.P3D)
 3    # drawing vertices in 3D requires P3D
 4    # as a parameter to size()
 5    s = py5.create_shape()
 6    s.begin_shape()
 7    s.vertex(30, 20, 10)
 8    s.vertex(85, 20, 10)
 9    s.vertex(85, 75, 10)
10    s.vertex(30, 75, 10)
11    s.end_shape(py5.CLOSE)
12    py5.shape(s)
example picture for vertex()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3    img = py5.load_image("tower.jpg")
 4    # call py5.texture_mode() here to inherit mode setting
 5    # py5.texture_mode(py5.NORMAL)
 6    s = py5.create_shape()
 7    s.begin_shape()
 8    s.texture(img)
 9    s.texture_mode(py5.NORMAL)
10    s.vertex(20, 20, 0, 0)
11    s.vertex(20, 80, 0, 1)
12    s.vertex(80, 80, 1, 1)
13    s.vertex(80, 20, 1, 0)
14    s.end_shape(py5.CLOSE)
15
16    py5.shape(s)

Description#

Add a new vertex to a Py5Shape object. All shapes are constructed by connecting a series of vertices. The vertex() method is used to specify the vertex coordinates for points, lines, triangles, quads, and polygons. It is used exclusively within the Py5Shape.begin_shape() and Py5Shape.end_shape() methods.

Drawing a vertex in 3D using the z parameter requires the P3D renderer, as shown in the second example.

This method is also used to map a texture onto geometry. The Py5Shape.texture() function declares the texture to apply to the geometry and the u and v coordinates define the mapping of this texture to the form. By default, the coordinates used for u and v are specified in relation to the image’s size in pixels, but this relation can be changed with the Py5Shape object’s Py5Shape.texture_mode() method or by calling the Sketch’s texture_mode() method before the shape is created.

Underlying Processing method: PShape.vertex

Syntax#

vertex(x: float, y: float, /) -> None
vertex(x: float, y: float, u: float, v: float, /) -> None
vertex(x: float, y: float, z: float, /) -> None
vertex(x: float, y: float, z: float, u: float, v: float, /) -> None

Parameters#

  • u: float - horizontal coordinate for the texture mapping

  • v: float - vertical coordinate for the texture mapping

  • x: float - x-coordinate of the vertex

  • y: float - y-coordinate of the vertex

  • z: float - z-coordinate of the vertex

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