bobzhang/p5/shape does not have a README file

    Path

    type Path = Array[PathCmd]

    A sequence of path commands.

    ArcAngles

    pub struct ArcAngles {
    start : Double
    stop : Double
    same_point : Bool
    }

    Normalized arc angles: start in [0, TWO_PI), stop in [start, start + TWO_PI), and whether both denote the same point.

    ArcMode

    pub(all) enum ArcMode {
    Open
    Chord
    Pie
    } derive(Eq,
    Debug
    )

    How arc() is closed. Without a mode, an arc is filled like a pie slice but its outline is left open.

    CloseMode

    pub(all) enum CloseMode {
    Open
    Close
    } derive(Eq,
    Debug
    )

    Whether end_shape / end_contour closes the path.

    PathCmd

    pub(all) enum PathCmd {
    MoveTo(Double, Double)
    LineTo(Double, Double)
    QuadraticCurveTo(Double, Double, Double, Double)
    BezierCurveTo(Double, Double, Double, Double, Double, Double)
    Ellipse(Double, Double, Double, Double, Double, Double, Double)
    Rect(Double, Double, Double, Double)
    RoundRect(Double, Double, Double, Double, Double, Double, Double, Double)
    ClosePath
    } derive(Eq,
    Debug
    )

    A canvas path command, mirroring the Path2D API.
    pub(all) struct Pt {
    x : Double
    y : Double
    z : Double
    extra : FixedArray[Double]
    } derive(Eq,
    Debug
    )

    A vertex: position plus extra per-vertex data (WEBGL mode flattens texture coordinates, normal, fill and stroke into extra; interpolated along curves like p5's vertexToArray/arrayToVertex).

    Pt::xy

    fn Pt::xy(x : Double, y : Double) -> Pt

    A 2D vertex without extra data.

    Shape

    pub struct Shape {
    // private fields
    }

    A shape under construction, built with begin_shape / vertex / end_shape like p5's p5.Shape.

    Shape::arc

    fn Shape::arc(self : Shape, x : Double, y : Double, w : Double, h : Double, start : Double, stop : Double, mode : ArcMode?) -> Unit

    Adds an arc primitive (bounding box x, y, w, h, angles in radians).

    Shape::begin_contour

    fn Shape::begin_contour(self : Shape, kind? : ShapeKind) -> Unit

    Starts a new contour.

    Shape::begin_shape

    fn Shape::begin_shape(self : Shape, kind? : ShapeKind) -> Unit

    Begins the shape (implicitly starts the first contour).

    Shape::bezier_vertex

    fn Shape::bezier_vertex(self : Shape, x : Double, y : Double) -> Unit

    Adds a Bézier vertex (bezierVertex(x, y)). In a path, the first vertex is an anchor and every bezier_order following vertices form a curve.

    Shape::bezier_vertex_pt

    fn Shape::bezier_vertex_pt(self : Shape, p : Pt) -> Unit

    Adds a Bézier control/anchor vertex with full data (WEBGL).

    Shape::ellipse

    fn Shape::ellipse(self : Shape, x : Double, y : Double, w : Double, h : Double) -> Unit

    Adds an ellipse primitive with bounding box x, y, w, h.

    Shape::end_contour

    fn Shape::end_contour(self : Shape, mode? : CloseMode) -> Unit

    Ends the current contour, closing it when mode is Close.

    Shape::end_shape

    fn Shape::end_shape(self : Shape, mode? : CloseMode) -> Unit

    Ends the shape. Close closes the first contour.

    Shape::first_contour_kind

    fn Shape::first_contour_kind(self : Shape) -> ShapeKind

    The kind of the first contour (p5's shape.contours[0].kind).

    Shape::kind

    fn Shape::kind(self : Shape) -> ShapeKind

    The kind of the shape (from begin_shape).

    Shape::line

    fn Shape::line(self : Shape, x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> Unit

    Adds a line primitive.

    Shape::new

    fn Shape::new() -> Shape

    Creates an empty shape.

    Shape::point

    fn Shape::point(self : Shape, x : Double, y : Double) -> Unit

    Adds a point primitive.

    Shape::quad

    fn Shape::quad(self : Shape, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double, x4 : Double, y4 : Double) -> Unit

    Adds a quad primitive.

    Shape::rect

    fn Shape::rect(self : Shape, x : Double, y : Double, w : Double, h : Double, radii? : (Double, Double, Double, Double)) -> Unit

    Adds a rectangle primitive, optionally with corner radii (top-left, top-right, bottom-right, bottom-left).

    Shape::reset

    fn Shape::reset(self : Shape) -> Unit

    Removes all contours.

    Shape::set_bezier_order

    fn Shape::set_bezier_order(self : Shape, order : Int) -> Unit

    Sets the order (2 = quadratic, 3 = cubic) used by bezier_vertex.

    Shape::set_spline_ends

    fn Shape::set_spline_ends(self : Shape, ends : SplineEnds) -> Unit

    Sets how spline ends are treated.

    Shape::set_spline_tightness

    fn Shape::set_spline_tightness(self : Shape, tightness : Double) -> Unit

    Sets the spline tightness (0 = Catmull-Rom).

    Shape::spline_vertex

    fn Shape::spline_vertex(self : Shape, x : Double, y : Double) -> Unit

    Adds a spline vertex (splineVertex(x, y)).

    Shape::spline_vertex_pt

    fn Shape::spline_vertex_pt(self : Shape, p : Pt) -> Unit

    Adds a spline vertex with full data (WEBGL).

    Shape::to_paths

    fn Shape::to_paths(self : Shape, has_fill? : Bool, has_stroke? : Bool) -> ShapePaths

    Converts the shape into canvas path commands.

    test {
    let s = @shape.Shape::new()
    s.begin_shape()
    s.vertex(0, 0)
    s.vertex(10, 0)
    s.vertex(10, 10)
    s.end_shape(mode=Close)
    debug_inspect(
    s.to_paths().path,
    content="[MoveTo(0, 0), LineTo(10, 0), LineTo(10, 10), ClosePath]",
    )
    }

    Shape::to_vertices

    fn Shape::to_vertices(self : Shape, curve_detail? : Double, points_to_lines? : Bool) -> Array[Array[Pt]]

    The shape as lists of vertices, one per contour or primitive, with curves sampled at curve_detail points per unit of hull length.

    Shape::triangle

    fn Shape::triangle(self : Shape, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double) -> Unit

    Adds a triangle primitive.

    Shape::vertex

    fn Shape::vertex(self : Shape, x : Double, y : Double) -> Unit

    Adds a vertex (vertex(x, y)).

    Shape::vertex_pt

    fn Shape::vertex_pt(self : Shape, p : Pt) -> Unit

    Adds a vertex with a z coordinate and extra data (WEBGL).

    ShapeKind

    pub(all) enum ShapeKind {
    Path
    Points
    Lines
    Triangles
    Quads
    TriangleFan
    TriangleStrip
    QuadStrip
    } derive(Eq,
    Debug
    )

    Kinds of shapes accepted by begin_shape() / begin_contour().

    ShapeMode

    pub(all) enum ShapeMode {
    Corner
    Corners
    Center
    Radius
    } derive(Eq,
    Debug
    )

    rectMode() / ellipseMode() / imageMode() values.

    ShapePaths

    pub struct ShapePaths {
    path : Array[PathCmd]
    fill : Array[PathCmd]?
    stroke : Array[PathCmd]?
    }

    The result of converting a shape for the 2D renderer: the base path, plus specialised fill / stroke paths when they differ (arcs).

    ShapePaths::fill_path

    fn ShapePaths::fill_path(self : ShapePaths) -> Array[PathCmd]

    The path to fill.

    ShapePaths::stroke_path

    fn ShapePaths::stroke_path(self : ShapePaths) -> Array[PathCmd]

    The path to stroke.

    SplineEnds

    pub(all) enum SplineEnds {
    Include
    Exclude
    Join
    } derive(Eq,
    Debug
    )

    How the ends of a spline are treated (splineProperty('ends', ...)).

    bezier_point

    fn bezier_point(a : Double, b : Double, c : Double, d : Double, t : Double) -> Double

    Evaluates one coordinate of a cubic Bézier curve at t.

    test {
    inspect(@shape.bezier_point(0, 0, 100, 100, 0.5), content="50")
    }

    bezier_tangent

    fn bezier_tangent(a : Double, b : Double, c : Double, d : Double, t : Double) -> Double

    Evaluates the derivative of one coordinate of a cubic Bézier at t.

    mode_adjust

    fn mode_adjust(a : Double, b : Double, c : Double, d : Double, mode : ShapeMode) -> (Double, Double, Double, Double)

    Normalizes the first four arguments of rect, ellipse and arc according to mode, returning the top-left corner and a positive size.

    test {
    debug_inspect(
    @shape.mode_adjust(50, 50, 20, 10, Center),
    content="(40, 45, 20, 10)",
    )
    debug_inspect(
    @shape.mode_adjust(30, 40, 10, 20, Corners),
    content="(10, 20, 20, 20)",
    )
    }

    normalize_arc_angles

    fn normalize_arc_angles(start : Double, stop : Double, w : Double, h : Double, correct_for_scaling? : Bool) -> ArcAngles

    Port of p5's _normalizeArcAngles. With correct_for_scaling, the angles are adjusted so they are measured on the ellipse of size w×h.

    spline_point

    fn spline_point(a : Double, b : Double, c : Double, d : Double, t : Double, tightness? : Double) -> Double

    Evaluates one coordinate of a Catmull-Rom spline segment between b and c at t, with the given tightness (0 by default).

    spline_tangent

    fn spline_tangent(a : Double, b : Double, c : Double, d : Double, t : Double, tightness? : Double) -> Double

    Evaluates the derivative of one coordinate of a spline segment at t.