module Shape:sig
..end
Shape
contains the Shape.t
type and utilities for creating and
manipulating shapes. A Shape.t
is a vector representation of a
drawing command and serves as the basis for all drawing operations
in p5ml.
type
tag = ..
tag
is an extensible variant for attaching arbitrary metadata to
shapes.
type
tag +=
| |
TName of |
type
vertex = private
| |
MoveTo of |
(* |
| *) |
| |
LineTo of |
(* |
| *) |
| |
BezierTo of |
(* |
| *) |
| |
Arc of |
(* |
| *) |
| |
ClosePath |
(* |
| *) |
The type of a vertex, a single piece of vector information that forms a shape.
type
t = private
| |
Shape of |
(* |
| *) |
| |
Group of |
(* |
| *) |
| |
Paint of |
(* |
| *) |
| |
Tag of |
(* |
| *) |
| |
Background of |
(* |
| *) |
| |
Empty |
(* |
| *) |
The type of a shape, a component that can be displayed.
The Shape
constructor contains vertices.
val poly : ?close:[ `Close | `Open ] -> Math.vector list -> t
poly vertices
is the shape representing the polygon with vertices
.
val point : Math.vector -> t
point vertex
is the shape representing the point at position vertex
.
val line : Math.vector -> Math.vector -> t
line v1 v2
is the shape representing the line between v1
and v2
.
val rect : Math.vector -> ?align:[ `Center | `Corner ] -> Math.vector -> t
rect point size
is the shape representing the rectangle with corner at
point
and dimensions size
.
val quad : Math.vector -> Math.vector -> Math.vector -> Math.vector -> t
quad v1 v2 v3 v3
is polygon [v1; v2; v3; v4]
.
val triangle : Math.vector -> Math.vector -> Math.vector -> t
triangle v1 v2 v3
is polygon [v1; v2; v3]
.
val ellipse : Math.vector -> ?align:[ `Center | `Corner ] -> Math.vector -> t
ellipse point size
is the shape representing the ellipse centered at
point
and inscribed in rect point ~align:`Center size
.
val circle : Math.vector -> ?align:[ `Center | `Corner ] -> float -> t
circle point radius
is ellipse point (radius, radius)
.
val arc : Math.vector ->
?align:[ `Center | `Corner ] ->
Math.vector ->
?stroke_mode:[ `Closed | `Open ] ->
?fill_mode:[ `Chord | `Pie ] -> ?phi:float -> float -> float -> t
arc point size theta1 theta2
is the shape representing the arc (portion
of a full ellipse) centered at point
and inscribed in
rect point ~align:`Center size
from angle theta1
to theta2
.
val bezier : Bezier.t -> t
bezier bez
is the shape representing the Bezier curve bez
.
val group : t list -> t
group shapes
is the shape that draws shapes
in order.
val shape : t -> Math.vector -> t
shape sh tr
is the shape sh
translated by tr
.
val background : Color.color -> t
background color
is the shape that sets the background to color
.
val empty : t
empty
is the shape that draws nothing.
val fill : Color.color -> t -> t
fill color shape
is shape
with fill color
, used to draw the inside
of shapes.
val no_fill : t -> t
no_fill shape
is shape
with fill cleared.
val stroke : Color.color -> t -> t
stroke color shape
is shape
with stroke color
, used to draw the
outline of shapes.
val no_stroke : t -> t
no_stroke shape
is shape
with stroke cleared.
val stroke_weight : float -> t -> t
stroke_weight w shape
is shape
with stroke weight w
, the width of
the stroke lines.
val stroke_cap : [ `Project | `Round | `Square ] -> t -> t
stroke_cap c shape
is shape
with stroke cap c
, the way that the ends
of lines are drawn.
val stroke_join : [ `Bevel | `Miter | `Round ] -> t -> t
stroke_join j shape
is shape
with stroke join j
, the way that vertices
between two lines are drawn.
val bleach : t -> t
bleach shape
is shape
with all color (fill or stroke) information
removed.
val name : string -> t -> t
name n shape
is shape
tagged with name n
, which can be looked up
with find_name
.
val find_name : string -> t -> t option
find_name name shape
is Some found
where found
is the first shape
tagged with name
in shape
, or None
if shape
contains no shapes
tagged name
.
val find_names : string -> t -> t list
find_names name shape
is the list of all shapes in shape
that are
tagged with name
.
val tag : tag -> t -> t
tag tg shape
is shape
tagged with tag tg
, which can be looked up with
find_tag
. Tags are a more general form of names.
val find_tag : ?eq:(tag -> tag -> bool) ->
tag -> t -> t option
find_tag tag shape
is Some found
where found
is the first shape tagged
with tag
in shape
, or None
if shape
contains no shapes tagged
tag
.
?eq:(tag -> tag -> bool) -> tag -> t -> t list
: find_tags tag shape
is the list of all shapes in shape
that are tagged
with tag
.
val translate : Math.vector -> t -> t
translate tr shape
is shape
translated by offset tr
.
val scale : Math.vector -> t -> t
scale (scale_x, scale_y) shape
is shape
scaled by factors of scale_x
and scale_y
in the x and y directions, respectively, about the origin.
To achieve scaling about a different center, first use translate
.
val rotate : float -> t -> t
rotate angle shape
is shape
rotated angle
radians about the origin.
To achieve rotation about a different center, first use translate
.