|
1 | 1 |
|
| 2 | +(** [Shape] contains the [Shape.t] type and utilities for creating and |
| 3 | + manipulating shapes. A [Shape.t] is a vector representation of a |
| 4 | + drawing command and serves as the basis for all drawing operations |
| 5 | + in p5ml. *) |
| 6 | + |
2 | 7 | open Color
|
3 | 8 | open Paint
|
4 | 9 | open Math
|
5 | 10 | open Bezier
|
6 | 11 |
|
| 12 | +(** {2 Shapes} *) |
| 13 | + |
7 | 14 | type vector = Vector.t
|
8 | 15 |
|
| 16 | +(** The type of a vertex, a single piece of vector information that |
| 17 | + forms a shape. *) |
9 | 18 | type vertex = private
|
| 19 | + (** [MoveTo vec] picks up the pen and places it down at [vec]. *) |
10 | 20 | | MoveTo of vector
|
| 21 | + |
| 22 | + (** [LineTo vec] draws from the pen location to [vec]. *) |
11 | 23 | | LineTo of vector
|
| 24 | + |
| 25 | + (** [BezierTo v2 v3 v4] draws from the pen location, using the pen location |
| 26 | + as the beginning anchor point, [v2] and [v3] as the anchor points, and |
| 27 | + [v4] as the ending anchor point. *) |
12 | 28 | | BezierTo of vector * vector * vector
|
| 29 | + |
| 30 | + (** [Arc center size phi theta1 theta2] draws an arc centered at [center] |
| 31 | + and inscribed in [rect point ~align:`Center size]. [phi] is the offset |
| 32 | + angle of the rectangle, and [theta1] and [theta2] are the start and end |
| 33 | + angles of the arc, respectively. The pen is not moved to the start; it |
| 34 | + continues from where it left off and connects to where the arc begins. *) |
13 | 35 | | Arc of vector * vector * float * float * float
|
| 36 | + |
| 37 | + (** [ClosePath] closes the path by drawing a line from the current pen |
| 38 | + position to the last pen down position (created by [MoveTo]). *) |
14 | 39 | | ClosePath
|
15 | 40 |
|
| 41 | +(** The type of a shape, a component that can be displayed. |
| 42 | + The [Shape] constructor contains vertices. *) |
16 | 43 | type t = private
|
| 44 | + (** [Shape vertices] is a complex shape defined by [vertices]. Well-formed |
| 45 | + shapes must begin with [MoveTo] and cannot have a [ClosePath] anywhere |
| 46 | + except (optionally) the end. *) |
17 | 47 | | Shape of vertex list
|
| 48 | + |
| 49 | + (** [Group shapes] is the compound shape that draws each shape in [shapes] |
| 50 | + in order, i.e. with the last shape on top. *) |
18 | 51 | | Group of t list
|
| 52 | + |
| 53 | + (** [Paint shape update] is the shape that draws [shape] with the paint |
| 54 | + modification specified by [update]. Paint updates are specified one |
| 55 | + attribute at a time (e.g. just the stroke) so that all other attributes |
| 56 | + are inherited from the parent shape. *) |
19 | 57 | | Paint of t * paint_update
|
| 58 | + |
| 59 | + (** [Name shape n] is [shape] tagged with name [n]. This shape is functionally |
| 60 | + equivalent to [shape], but the name may be used for identifying small |
| 61 | + components of larger shapes. *) |
20 | 62 | | Name of t * string
|
| 63 | + |
| 64 | + (** [Background color] is the shape that fills the background with [color], |
| 65 | + erasing what was already present. This separate constructor is necessary |
| 66 | + because a [rect] would be affected by transformations. *) |
21 | 67 | | Background of color
|
| 68 | + |
| 69 | + (** [Empty] is the shape that draws nothing. *) |
22 | 70 | | Empty
|
23 | 71 |
|
| 72 | +(** {2 Constructing Basic Shapes} *) |
| 73 | + |
| 74 | +(** [poly vertices] is the shape representing the polygon with [vertices]. *) |
24 | 75 | val poly : ?close : [`Close | `Open] -> vector list -> t
|
| 76 | + |
| 77 | +(** [point vertex] is the shape representing the point at position [vertex]. *) |
25 | 78 | val point : vector -> t
|
| 79 | + |
| 80 | +(** [line v1 v2] is the shape representing the line between [v1] and [v2]. *) |
26 | 81 | val line : vector -> vector -> t
|
| 82 | + |
| 83 | +(** [rect point size] is the shape representing the rectangle with corner at |
| 84 | + [point] and dimensions [size]. *) |
27 | 85 | val rect : vector -> ?align : [`Corner | `Center] -> vector -> t
|
| 86 | + |
| 87 | +(** [quad v1 v2 v3 v3] is [polygon [v1; v2; v3; v4]]. *) |
28 | 88 | val quad : vector -> vector -> vector -> vector -> t
|
| 89 | + |
| 90 | +(** [triangle v1 v2 v3] is [polygon [v1; v2; v3]]. *) |
29 | 91 | val triangle : vector -> vector -> vector -> t
|
| 92 | + |
| 93 | +(** [ellipse point size] is the shape representing the ellipse centered at |
| 94 | + [point] and inscribed in [rect point ~align:`Center size]. *) |
30 | 95 | val ellipse : vector -> ?align : [`Corner | `Center] -> vector -> t
|
| 96 | + |
| 97 | +(** [circle point radius] is [ellipse point (radius, radius)]. *) |
31 | 98 | val circle : vector -> ?align : [`Corner | `Center] -> float -> t
|
| 99 | + |
| 100 | +(** [arc point size theta1 theta2] is the shape representing the arc (portion |
| 101 | + of a full ellipse) centered at [point] and inscribed in |
| 102 | + [rect point ~align:`Center size] from angle [theta1] to [theta2]. *) |
32 | 103 | val arc : vector -> ?align : [`Corner | `Center] -> vector ->
|
33 | 104 | ?stroke_mode : [`Closed | `Open] ->
|
34 | 105 | ?fill_mode : [`Pie | `Chord] -> ?phi : float -> float -> float -> t
|
| 106 | + |
| 107 | +(** [bezier bez] is the shape representing the Bezier curve [bez]. *) |
35 | 108 | val bezier : Bezier.t -> t
|
36 | 109 |
|
| 110 | +(** {2 Constructing Meta-shapes} *) |
| 111 | + |
| 112 | +(** [group shapes] is the shape that draws [shapes] in order. *) |
37 | 113 | val group : t list -> t
|
| 114 | + |
| 115 | +(** [shape sh tr] is the shape [sh] translated by [tr]. *) |
38 | 116 | val shape : t -> vector -> t
|
| 117 | + |
| 118 | +(** [background color] is the shape that sets the background to [color]. *) |
39 | 119 | val background : color -> t
|
| 120 | + |
| 121 | +(** [empty] is the shape that draws nothing. *) |
40 | 122 | val empty : t
|
41 | 123 |
|
| 124 | +(** {2 Applying Shape Paints} *) |
| 125 | + |
| 126 | +(** [fill color shape] is [shape] with fill [color], used to draw the inside |
| 127 | + of shapes. *) |
42 | 128 | val fill : color -> t -> t
|
| 129 | + |
| 130 | +(** [no_fill shape] is [shape] with fill cleared. *) |
43 | 131 | val no_fill : t -> t
|
| 132 | + |
| 133 | +(** [stroke color shape] is [shape] with stroke [color], used to draw the |
| 134 | + outline of shapes. *) |
44 | 135 | val stroke : color -> t -> t
|
| 136 | + |
| 137 | +(** [no_stroke shape] is [shape] with stroke cleared. *) |
45 | 138 | val no_stroke : t -> t
|
| 139 | + |
| 140 | +(** [stroke_weight w shape] is [shape] with stroke weight [w], the width of |
| 141 | + the stroke lines. *) |
46 | 142 | val stroke_weight : float -> t -> t
|
| 143 | + |
| 144 | +(** [stroke_cap c shape] is [shape] with stroke cap [c], the way that the ends |
| 145 | + of lines are drawn. *) |
47 | 146 | val stroke_cap : [`Round | `Square | `Project] -> t -> t
|
| 147 | + |
| 148 | +(** [stroke_join j shape] is [shape] with stroke join [j], the way that vertices |
| 149 | + between two lines are drawn. *) |
48 | 150 | val stroke_join : [`Miter | `Bevel | `Round] -> t -> t
|
49 | 151 |
|
| 152 | +(** {2 Names} *) |
| 153 | + |
| 154 | +(** [name n shape] is [shape] tagged with name [n], which can be looked up |
| 155 | + with [find_named]. *) |
50 | 156 | val name : string -> t -> t
|
51 | 157 |
|
52 |
| -val find_named : t -> string -> t option |
| 158 | +(** [find_named name shape] is [Some found] where [found] is the first shape |
| 159 | + tagged with [name] in [shape], or [None] if [shape] contains no shapes |
| 160 | + tagged [name]. *) |
| 161 | +val find_named : string -> t -> t option |
53 | 162 |
|
| 163 | +(** [find_all_named name shape] is the list of all shapes in [shape] that are |
| 164 | + tagged with [name]. *) |
| 165 | +val find_all_named : string -> t -> t list |
| 166 | + |
| 167 | +(** {2 Transformations} *) |
| 168 | + |
| 169 | +(** [translate tr shape] is [shape] translated by offset [tr]. *) |
54 | 170 | val translate : vector -> t -> t
|
| 171 | + |
| 172 | +(** [scale (scale_x, scale_y) shape] is [shape] scaled by factors of [scale_x] |
| 173 | + and [scale_y] in the x and y directions, respectively, about the origin. |
| 174 | + To achieve scaling about a different center, first use [translate]. *) |
55 | 175 | val scale : vector -> t -> t
|
| 176 | + |
| 177 | +(** [rotate angle shape] is [shape] rotated [angle] radians about the origin. |
| 178 | + To achieve rotation about a different center, first use [translate]. *) |
56 | 179 | val rotate : float -> t -> t
|
0 commit comments