- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Class | PShape
Name | ### setVertex()
Examples |
    PShape s;

    void setup() {
      size(100, 100);
      s = createShape();
      s.beginShape();
      s.vertex(0, 0);
      s.vertex(60, 0);
      s.vertex(60, 60);
      s.vertex(0, 60);
      s.endShape(CLOSE);
    }

    void draw() {
      translate(20, 20);
      for (int i = 0; i < s.getVertexCount(); i++) {
        PVector v = s.getVertex(i);
        v.x += random(-1, 1);
        v.y += random(-1, 1);
        s.setVertex(i, v);
      }
      shape(s);
    }
Description | The setVertex() method defines the coordinates of the vertex point located at the position defined by the index parameter. This method works when shapes are created as shown in the example above, but won't work properly when a shape is defined explicitly (e.g. createShape(RECT, 20, 20, 80, 80).
Syntax |
    sh.setVertex(index, x, y)
    sh.setVertex(index, x, y, z)
    sh.setVertex(index, vec)
Parameters |
sh | PShape: any variable of type PShape
index | int: the location of the vertex
x | float: the x value for the vertex
y | float: the y value for the vertex
z | float: the z value for the vertex
vec | PVector: the PVector to define the x, y, z coordinates
Returns | void
Related | getVertex() getVertexCount()

Updated on July 4, 2018 11:56:45am EDT