2D primitives

Rect, ellipse, arc, and custom-shape drawing all share the same four-argument alignment convention, resolved by ShapeAlignMode.

2D

On this page · 14 entries

RectMode / EllipseMode / ShapeMode(ShapeAlignMode mode)

Sets how the four arguments are interpreted. Default is Corner for rect and shape, Center for ellipse.

modea, b, c, d mean
Cornerx, y, width, height
Cornersx1, y1, x2, y2 (opposite corners)
Centercenter x, center y, width, height
Radiuscenter x, center y, x-radius, y-radius

Rect · Ellipse

  • Rect(a, b, c, d)
  • Ellipse(a, b, c, d)

Draws per the active mode, filled and/or stroked.

Rect

  • Rect(a, b, c, d, r)
  • Rect(a, b, c, d, tl, tr, br, bl)

Rounded corners, like Processing's rect(x, y, w, h, r): one radius for all four, or one per corner (top-left, top-right, bottom-right, bottom-left). No radius can be more than half the shorter side.

Square

  • Square(x, y, extent)

A Rect with equal width and height — a plain alias, still subject to the current RectMode().

Circle

  • Circle(x, y, extent)

An Ellipse with equal width and height — a plain alias for Ellipse(x, y, extent, extent), still subject to the current EllipseMode().

Line · Point

  • Line(x1, y1, x2, y2)
  • Point(x, y)

A straight stroked segment, or a single point.

Triangle · Polygon · Quad

  • Triangle(x1,y1, x2,y2, x3,y3)
  • Polygon(...)
  • Quad(...)

Polygon closes and fills/strokes an arbitrary point list.

Arc

  • Arc(a, b, c, d, start, stop, mode = ArcMode.Open)

Draws an arc of the ellipse bounded per EllipseMode.

ArcMode
OpenJust the curved arc, unconnected.
ChordArc closed with a straight line between ends.
PieArc closed through the center — a wedge.

Bezier

  • Bezier(x1,y1, cx1,cy1, cx2,cy2, x2,y2)

Draws a cubic Bézier curve, stroked only.

BezierPoint · BezierTangent

  • BezierPoint(...)
  • BezierTangent(...) → float

Evaluate one axis of a cubic Bézier at parameter t.

Curve · CurveTightness

  • Curve(x1,y1, x2,y2, x3,y3, x4,y4)
  • CurveTightness(float t)

A Catmull-Rom curve through four points.

CurvePoint · CurveTangent

  • CurvePoint(...)
  • CurveTangent(...) → float

Evaluate one axis of a Catmull-Rom curve at parameter t, the way Curve()/CurveVertex() shape it. Always uses the standard tension — unlike Curve() itself, this doesn't read CurveTightness(), matching Processing's own curvePoint().

BezierDetail · CurveDetail

  • BezierDetail(int detail)
  • CurveDetail(int detail)

Stored for API parity with sketches ported from Processing. Skia already draws exact, analytically-flattened Bézier/Catmull-Rom curves regardless of segment count, so neither has any visible effect here.

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#
// The basic shapes, with stroke and fill.
public class Primitives : Sketch
{
    public override void Setup() => Size(640, 260);

    public override void Draw()
    {
        Background(250, 246, 240);
        Stroke(40);
        StrokeWeight(3);
        Fill(255, 170, 120);

        Point(30, 130);
        Line(60, 60, 120, 200);
        Rect(140, 60, 90, 140);
        Square(250, 90, 80);
        Ellipse(400, 130, 110, 70);
        Circle(520, 130, 90);
        Triangle(560, 220, 600, 150, 630, 220);
        Arc(400, 220, 80, 80, 0, PI, ArcMode.Pie);

        NoFill();
        StrokeWeight(1);
        Quad(20, 20, 600, 30, 610, 40, 30, 40);
    }
}