Custom shapes & meshes
Build arbitrary shapes vertex by vertex. There are two render paths at EndShape(): a simple path when every vertex shares one fill color, and a mesh path (Gouraud shading and/or texturing) once either varies.
On this page · 9 entries
BeginShape
BeginShape(ShapeKind kind = Polygon)
Starts recording vertices. See ShapeKind for all interpretations.
Vertex
Vertex(x, y)Vertex(x, y, u, v)
Adds a vertex, colored by the current Fill() at the moment of the call. The UV overload adds texture coordinates.
BezierVertex · QuadraticVertex
BezierVertex(...)QuadraticVertex(...)
Adds a curved segment to a Polygon-mode shape.
CurveVertex
CurveVertex(x, y)
Adds a Catmull-Rom curve vertex, respecting CurveTightness(). As in Processing, the curve only passes through the interior points — the very first and very last CurveVertex() calls shape the tangent at each end but aren't drawn to themselves, so nothing appears until the 4th call. The common pattern is to repeat the first and last point once so the curve visibly starts/ends there.
BeginContour · EndContour
BeginContour()EndContour()
Cuts a hole in the shape currently being built — the vertices recorded between these two calls form a subpath that's subtracted from the outline, like a donut. Only valid in the default Polygon mode of BeginShape().
BeginContour() switches that shape's fill rule to even-odd so the hole punches through reliably regardless of winding direction. Shapes that never call it keep the usual winding rule and render exactly as before.Texture · NoTexture
Texture(PImage img)NoTexture()
Sets or clears the texture image for the shape.
TextureMode · TextureWrap
TextureMode(TextureModeKind mode)TextureWrap(TextureWrapKind mode)
Sets how Vertex(x, y, u, v)'s u/v are interpreted, and how a texture samples outside its 0–1 range. See TextureModeKind / TextureWrapKind.
Normal (0–1 UVs), not Processing's own default of Image (pixel-coordinate UVs) — Vertex(x, y, u, v) already treated its u/v as 0–1 before TextureMode() existed, so the default was kept for backward compatibility. Call TextureMode(Image) for Processing's real default behavior.EndShape
EndShape(bool close = false)
Finishes and draws the recorded shape.
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.
// BeginShape/Vertex/EndShape: a star whose points follow the mouse. public class Star : Sketch { public override void Setup() => Size(500, 500); public override void Draw() { Background(20, 24, 40); float inner = Map(MouseX, 0, Width, 30, 180); int points = (int)Map(MouseY, 0, Height, 3, 12); Fill(255, 210, 90); Stroke(255); StrokeWeight(2); BeginShape(); for (int i = 0; i < points * 2; i++) { float r = i % 2 == 0 ? 200 : inner; float a = i * PI / points - HALF_PI; Vertex(Width / 2 + Cos(a) * r, Height / 2 + Sin(a) * r); } EndShape(close: true); // A smooth curve through points. NoFill(); Stroke(120, 200, 255); BeginShape(); for (int x = -50; x <= Width + 50; x += 50) CurveVertex(x, 460 + Sin(x * 0.02f + FrameCount * 0.05f) * 20); EndShape(); } }