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

Name

PShape

Examples
PShape s;

void setup() {
  size(100, 100);
  // The file "bot.svg" must be in the data folder
  // of the current sketch to load successfully
  s = loadShape("bot.svg");
}

void draw() {
  shape(s, 10, 10, 80, 80);
}

PShape s;

void setup() {
  size(100, 100, P3D);
  // The file "bot.obj" must be in the data folder
  // of the current sketch to load successfully
  s = loadShape("bot.obj");
}

void draw() {
  background(204);
  translate(width/2, height/2);
  shape(s, 0, 0);
}
Description Datatype for storing shapes. Processing can currently load and display SVG (Scalable Vector Graphics) and OBJ shapes. Before a shape is used, it must be loaded with the loadShape() function. The shape() function is used to draw the shape to the display window. The PShape object contains a group of methods, linked below, that can operate on the shape data. OBJ files can only be opened using the P3D renderer.

The loadShape() function supports SVG files created with Inkscape and Adobe Illustrator. It is not a full SVG implementation, but offers some straightforward support for handling vector data.
Fields
width Shape document width
height Shape document height
Methods
isVisible() Returns a boolean value "true" if the image is set to be visible, "false" if not
setVisible() Sets the shape to be visible or invisible
disableStyle() Disables the shape's style data and uses Processing styles
enableStyle() Enables the shape's style data and ignores the Processing styles
beginContour() Starts a new contour
endContour() Ends a contour
endShape() Finishes the creation of a new PShape
getChild() Returns a child element of a shape as a PShape object
addChild() Adds a new child
getVertexCount() Returns the total number of vertices as an int
getVertex() Returns the vertex at the index position
setVertex() Sets the vertex at the index position
translate() Displaces the shape
rotateX() Rotates the shape around the x-axis
rotateY() Rotates the shape around the y-axis
rotateZ() Rotates the shape around the z-axis
rotate() Rotates the shape
scale() Increases and decreases the size of a shape
resetMatrix() Replaces the current matrix of a shape with the identity matrix
Constructor
PShape()
RelatedloadShape()
createShape()
shapeMode()
Updated on February 19, 2013 07:58:56pm EST

Creative Commons License