PShape

A loaded or built vector shape. Four ways to get one: load an SVG, build a primitive or group in code, or — under the 3D renderer — build a reusable mesh with CreateShape3D(). A given PShape is either a 2D SKPicture or a 3D mesh handle, never both.

On this page · 5 entries

LoadShape

  • LoadShape(string path) → PShape

Loads an SVG file.

CreateShape

  • CreateShape(PShapeType type, params float[] v) → PShape

Builds a standalone, reusable primitive shape in code, like Processing's createShape(RECT/ELLIPSE/LINE/TRIANGLE/QUAD, ...). x/y/w/h are in the shape's own local coordinate system — Shape(built, drawX, drawY) later draws it translated by (drawX, drawY), so it ends up on screen at (drawX + x, drawY + y), matching real Processing. Captures the current Fill()/Stroke()/StrokeWeight() as the shape's fixed, baked-in style — changing them afterward has no retroactive effect.

PShapeType
Rect4 values: x, y, w, h.
Ellipse4 values: x, y, w, h.
Line4 values: x1, y1, x2, y2.
Triangle6 values: x1,y1, x2,y2, x3,y3.
Quad8 values: x1,y1, x2,y2, x3,y3, x4,y4.

CreateShape

  • CreateShape(params PShape[] children) → PShape

Groups several 2D shapes into one, like Processing's createShape(GROUP) followed by addChild() for each piece. Each child keeps the absolute local coordinates it was built with — build a rocket out of a triangle, a rect, and an ellipse once in Setup(), then stamp the whole group with a single Shape() call per instance in Draw().

2D only. Group a set of CreateShape3D() meshes by drawing each with its own Shape() call instead — there's no 3D-mesh grouping yet.

Shape

  • Shape(PShape shape, x, y)
  • Shape(shape, x, y, w, h)

Draws the shape, positioned/sized per the current ShapeMode. Dispatches automatically to the 3D draw path when shape wraps a mesh from CreateShape3D() — see Custom 3D shapes.

Tint doesn't apply here. To tint a vector shape, render it into a PGraphics first.

Runnable example

A complete sketch using this section. Test in Dana opens it in the IDE, or paste it into a new tab and press Run.

C#
// PShape: build a shape once, draw it many times. LoadShape("icon.svg") loads SVGs.
public class Shapes : Sketch
{
    PShape flower;

    public override void Setup()
    {
        Size(600, 400);
        Fill(255, 140, 160);
        Stroke(120, 40, 60);
        var petals = new List<PShape>();
        for (int i = 0; i < 6; i++)
        {
float a = i * TWO_PI / 6;
petals.Add(CreateShape(PShapeType.Ellipse, 30 + Cos(a) * 18 - 12, 30 + Sin(a) * 18 - 12, 24, 24));
        }
        Fill(255, 220, 90);
        petals.Add(CreateShape(PShapeType.Ellipse, 22, 22, 16, 16));
        flower = CreateShape(petals.ToArray());
    }

    public override void Draw()
    {
        Background(235, 245, 230);
        RandomSeed(1);
        for (int i = 0; i < 40; i++)
        {
float s = Random(30, 90);
Shape(flower, Random(Width), Random(Height), s, s);
        }
        Shape(flower, MouseX - 50, MouseY - 50, 100, 100);
    }
}