Drawing Utensils
5.1 Color
5.2 Pen
5.3 Brush
5.4 Font
5.5 Region
5.6 Path
On this page:
Path
Path.close
Path.is_  open
Path.reset
Path.move_  to
Path.line_  to
Path.curve_  to
Path.lines
Path.polygon
Path.rectangle
Path.rounded_  rectangle
Path.ellipse
Path.arc
Path.text_  outline
Path.scale
Path.rotate
Path.translate
Path.transform
Path.append
Path.reverse
Path.bounding_  box
Path.handle
Path.from_  handle
0.45+9.0.900

5.6 Path🔗ℹ

A Path represents a set of figures defined by curves. A path can be used with the DC.path method of a drawing context to draw the path’s curves as lines, fill the region bounded by the path’s curves, or both. A path can also be used with the Region.path method to generate a region bounded by the path’s curves.

A path consists of zero or more closed subpaths, and possibly one open subpath. Some Path methods extend the open subpath, some methods close the open subpath, and some methods add closed subpaths. This approach to drawing formulation is inherited from PostScript.

When a path is drawn as a line, a closed subpath is drawn as a closed figure, analogous to a polygon. An open subpath is drawn with disjoint start and end points, analogous lines drawn with DC.lines.

When a path is filled or used as a region, the open subpath (if any) is treated as if it were closed. The content of a path is determined either through the #'even_odd rule or the #'winding rule, as selected at the time when the path is filled or used to generate a region.

A path is not connected to any particular DC object, so setting a DC transformation does not affect path operations. Instead, a DC’s transformation applies at the time that the path is drawn or used to set a region.

class

class draw.Path()

Creates an empty set of drawing paths.

method

method (path :: draw.Path).close() :: Void

 

method

method (path :: draw.Path).is_open() :: Boolean

 

method

method (path :: draw.Path).reset() :: Void

Closes an open subpath, if any, check whether a subpath is currently open, or discards all points to reset the path.

method

method (path :: draw.Path).move_to(pt :: PointLike)

  :: Void

 

method

method (path :: draw.Path).line_to(pt :: PointLike)

  :: Void

 

method

method (path :: draw.Path).curve_to(pt1 :: PointLike,

                                    pt2 :: PointLike,

                                    pt3 :: PointLike)

  :: Void

Sets a starting point for an open subpath, or extends an open path with a straight line or Bezier curve.

method

method (path :: draw.Path).lines(

  [pt :: PointLike, ...],

  ~dpt: dpt :: PointLike = Point.zero,

  ~dx: dx :: Real = 0,

  ~dy: dy :: Real = 0

) :: Void

Adds multiple lines to an open path in the same way as Path.line_to. Each point is shifted by dpt, dx, and dy.

method

method (path :: draw.Path).polygon(

  [pt :: PointLike, ...],

  ~dpt: dpt :: PointLike = Point.zero,

  ~dx: dx :: Real = 0,

  ~dy: dy :: Real = 0

) :: Void

Closes an open subpath, if any, adds lines to a new subpath like Path.lines, and then closes the open subpath.

method

method (path :: draw.Path).rectangle(r :: RectLike)

  :: Void

Closes the open subpath, if any, and adds a closed subpath that represents a rectangle r. (This convenience method is implemented in terms of Path.close, Path.move_to, and Path.line_to.)

method

method (path :: draw.Path).rounded_rectangle(

  r :: RectLike,

  radius :: Real = -0.25

) :: Void

Closes the open subpath, if any, and adds a closed subpath that represents a round-cornered rectangle bound by r. (This convenience method is implemented in terms of Path.close, Path.move_to, Path.line_to, and Path.arc.)

If radius is positive, the value is used as the radius of the rounded corner. If radius is negative, the absolute value is used as the proportion of the smallest dimension of the rectangle.

If radius is less than -0.5 or more than half of the width or height (respectively) of r, then half of the width or height (respectively) of r is used, instead.

method

method (path :: draw.Path).ellipse(

  r :: RectLike

) :: Void

Closes the open subpath, if any, and adds a closed subpath that represents an ellipse bounded by r. (This convenience method is implemented in terms of Path.close, Path.move_to, and Path.arc.)

method

method (path :: draw.Path).arc(

  r :: RectLike,

  start_radians :: Real,

  end_radians :: Real,

  ~clockwise: clockwise :: Any = #false

) :: Void

Extends or starts the path’s open subpath with a curve that corresponds to a section of an ellipse bounded by r. The ellipse section starts at the angle start_radians (0 is three o’clock and math.pi/2 is twelve o’clock) and continues to the angle end_radians. If clockwise is true, then the arc runs clockwise from start_radians to end_radians, otherwise it runs clockwise.

If the path has no open subpath, a new one is started with the arc’s starting point. Otherwise, the arc extends the existing sub-path, and the existing path is connected with a line to the arc’s starting point.

method

method (path :: draw.Path).text_outline(

  str :: String,

  ~dpt: dpt :: Point = Point.zero,

  ~dx: dx :: Real = 0,

  ~dy: dy :: Real = 0,

  ~font: font :: Font = Font(),

  ~combine: combine :: DC.TextCombine = #'kern

) :: Void

Closes the open subpath, if any, and adds a closed subpath to outline str using font. The top left of the text is positioned at dpt plus dx and dy. The combine argument enables kerning and character combination; see DC.TextCombine.

method

method (path :: draw.Path).scale(s :: Real) :: Void

 

method

method (path :: draw.Path).scale(sx :: Real, sy :: Real) :: Void

 

method

method (path :: draw.Path).rotate(radians :: Real) :: Void

 

method

method (path :: draw.Path).translate(dx :: Real, dy :: Real) :: Void

 

method

method (path :: draw.Path).transform(t :: Transformation) :: Void

Adjusts a path to scale, rotate, translate, or transform every point defining the path.

method

method (path :: draw.Path).append(other_path :: draw.Path) :: Void

Adds other_path to the end of path.

Closed subpaths of path are added as closed subpaths to path. If both paths have an open subpath, then this path’s open subpath is extended by the given path’s open subpath, adding a line from this path’s current ending point to the given path’s starting point. If only one of the paths has an open subpath, then it becomes (or remains) the path’s open subpath.

method

method (path :: draw.Path).reverse() :: Void

Reverses the direction of all subpaths within path. If the path has an open subpath, the starting point becomes the ending point, and extensions to the open sub-path build on this new ending point. Reversing a closed subpath affects how it combines with other subpaths when determining the content of a path in #'winding mode.

method

method (path :: draw.Path).bounding_box() :: Rect

Returns a rectangle that bounds all of the points describing path.

property

property (path :: draw.Path).handle :: Any

 

function

fun draw.Path.from_handle(hand :: Any) :: Path

The Path.handle property returns a Racket object that corresponds to the path for use directly with racket/draw. The Path.from_handle function creates a Path from such a Racket object.