1Prima::Drawable::Path(3U)ser Contributed Perl DocumentatiPornima::Drawable::Path(3)
2
3
4
6 Prima::Drawable::Path - stroke and fill complex paths
7
9 The module augments the "Prima::Drawable" drawing and plotting
10 functionality by implementing paths that allow arbitrary combination of
11 polylines, splines, and arcs, to be used for drawing or clipping
12 shapes.
13
15 # draws elliptic spiral
16 my ( $d1, $dx ) = ( 0.8, 0.05 );
17 $canvas-> new_path->
18 scale(200, 100)->
19 rotate(45)->
20 arc( 0, 0, $d1 + $dx * 0, $d1 + $dx * 1, 0, 90)->
21 arc( 0, 0, $d1 + $dx * 2, $d1 + $dx * 1, 90, 180)->
22 arc( 0, 0, $d1 + $dx * 2, $d1 + $dx * 3, 180, 270)->
23 arc( 0, 0, $d1 + $dx * 4, $d1 + $dx * 3, 270, 360)->
24 stroke;
25
27 Primitives
28 All primitives come in two versions, with absolute and relative
29 coordinates. The absolute version draws a graphic primitive so that
30 its starting point (or a reference point) is at (0,0). The relative
31 version, called with an 'r' (f.ex. "line" vs "rline") has its starting
32 point as the ending point of the previous primitive (or (0,0) if
33 there's none).
34
35 arc CENTER_X, CENTER_Y, DIAMETER_X, DIAMETER_Y, ANGLE_START, ANGLE_END,
36 TILT = 0
37 Adds elliptic arc to path centered around (CENTER_X,CENTER_Y).
38
39 circular_arc ANGLE_START, ANGLE_END
40 Adds circular arc to the path. Note that adding transformations
41 will effectively make it into elliptic arc, which is used
42 internally by "arc" and "rarc".
43
44 ellipse CENTER_X, CENTER_Y, DIAMETER_X, DIAMETER_Y = DIAMETER_X, TILT =
45 0
46 Adds full ellipse to the path.
47
48 line, rline @POINTS
49 Adds a polyline to path
50
51 rarc DIAMETER_X, DIAMETER_Y, ANGLE_START, ANGLE_END, TILT = 0
52 Adds elliptic arc to path so that the first point of the arc starts
53 on the last point of the previous primitive, or (0,0) if there's
54 none.
55
56 spline, rspline $POINTS, %OPTIONS.
57 Adds B-spline to path. See "spline" in Prima::Drawable for %OPTIONS
58 descriptions.
59
60 Transformations
61 Transformation calls change the current path properties (matrix etc) so
62 that all subsequent calls will use them until a call to "restore" is
63 used. "save" and "restore" implement a stacking mechanism, so that
64 local transformations can be made.
65
66 The final transformations calculate coordinates the new and the
67 existing matrices:
68
69 P' = NewMatrix * P
70
71 matrix A, B, C, D, Tx, Ty
72 Applies transformation matrix to the path. The matrix, as used by
73 the module, is formed as such:
74
75 A B 0
76 C D 0
77 Tx Ty 1
78
79 and when applied to 2D coordinates, is calculated as
80
81 X' = AX + CY + Tx
82 Y' = BX + DY + Ty
83
84 precision INTEGER
85 Selects current precision for splines and arcs. See "spline" in
86 Prima::Drawable, "precision" entry.
87
88 restore
89 Pops the stack entry and replaces the current matrix and graphic
90 properties with it.
91
92 rotate ANGLE
93 Adds rotation to the current matrix
94
95 save
96 Duplicates the current matrix and graphic properties and pushes
97 them to the stack.
98
99 shear X, Y = X
100 Adds shearing to the current matrix
101
102 scale X, Y = X
103 Adds scaling to the current matrix
104
105 translate X, Y = X
106 Adds offset to the current matrix
107
108 Operations
109 These methods perform actual path rendering, that was delayed until
110 that, and will create an array of points that can be used for actual
111 drawing.
112
113 clip %options
114 Returns 1-bit image with clipping mask of the path. %options can be
115 used to pass "fillWinding" property that affects the result of the
116 filled shape.
117
118 extents
119 Returns 2 points that box the path.
120
121 points
122 Runs all accumulated commands, and returns rendered set of points,
123 suitable for further calls to "Prima::Drawable::polyline" and
124 "Prima::Drawable::fillpoly".
125
126 last_matrix
127 Return CTM resulted after running all commands
128
129 fill
130 Paints a filled shape over the path
131
132 stroke
133 Draws a polyline over the path
134
135 region WINDING=0
136 Creates a region object from polygonal shape. If WINDING is set,
137 applies fill winding mode (see "fillWinding" in Drawable for more).
138
139 Methods for custom primitives
140 append PATH
141 Copies all commands from another PATH object. The PATH object
142 doesn't need to have balanced stacking brackets "save" and
143 "restore", and can be viewed as a macro.
144
145 identity
146 Returns identity matrix
147
148 matrix_apply @POINTS
149 Applies current matrix to POINTS, returns the transformed points.
150 If @POINTS is a list, returns list; if it is an array reference,
151 returns array reference.
152
154 Dmitry Karasik, <dmitry@karasik.eu.org>.
155
157 Prima::Drawable
158
159
160
161perl v5.28.0 2017-05-15 Prima::Drawable::Path(3)